Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Not Exists and in


Message #1 by kijjag@p... on Thu, 17 May 2001 19:59:40
Anita:
    Thank you very much. It's working 

> USE cursor
> Like
> Create Procedure tmpyear
> AS
> Declare @tempyear varchar(4)
> Declare curyear cursor  For Select Distinct Year  From Report ORDER BY 
year
>          OPEN curYear
>          Fetch NEXT From curYear INTO @tempyear
>          WHILE @@FETCH_STATUS=0
>          BEGIN
> 
>                  SELECT util_id,@tempyear AS Year FROM utility where 
> util_id  not in (select util_id from
>           report where year=@tempYear)
>          Print @tempyear
>          FETCH NEXT FROM curYear  INTO @tempYear
> 
>          END
> CLOSE curyear
> 
> DEALLOCATE curYear
> 
> Try it.
> Good Luck
> At 02:37 PM 5/18/01 +0000, you wrote:
> >Anita:
> >Thank you for your help.
> >But I still need to be able to give the range of util_id start from one 
to
> >many utilities with the same range of year (one to many). I don't have 
any
> >problem if users picked only one year and one utility.
> >
> >
> > > Try this:
> > > Create stored procedure <procedurename>
> > > @tempyear               varchar(4) or whatever in the table structure
> > > AS
> > > Select util_id From utility where util_id  not in (select util_id 
from
> > > report where year='"+@tempYear+"'")
> > > good luck!!!!
> > >
> > >
> > > At 07:59 PM 5/17/01 +0000, you wrote:
> > > >I'm trying to write the stored procedure that return the recordset 
with
> > > >missing report. I have 2 tables
> > > >
> > > >utility
> > > >util_id util_name
> > > >   10     aaa
> > > >   20     bbb
> > > >   30     ccc
> > > >   40     ddd
> > > >
> > > >report
> > > >   year   util_id
> > > >   2000    10
> > > >   2000    20
> > > >   1999    10
> > > >   1999    20
> > > >   1999    30
> > > >   1999    40
> > > >
> > > >I would like to know that utility id (10,20,30) in year (2000,1999)
> > > >who did not file the report.
> > > >
> > > >Thank you.
> > > >
> > > >
> > > >
> > > >

  Return to Index