Feb 26, 2010

Dyamically Creating Id Column And Increment For Each Row Automatically

declare @tab table(id int identity (0,1), moviename  varchar(200), movieid varchar(200),
showdate varchar(100),showtime datetime )INSERT INTO @tab select distinct top 4 m.moviename,m.movieid,convert(char(11), s.showtime, 106 ) as showdate,
convert(char(10), s.showtime, 111 ) as showtime  from tblshow s,tbltheater t,tblmovie m
where m.movieid=s.movieid and s.theaterid=t.theaterid and m.movieid=833
and convert(char(10), s.showtime, 111 )>=CONVERT(VARCHAR(10),GETDATE(),111)
order by showtime  asc select * from @tab

o/p:

0    MAA NANNA CHIRANJEEVI    833    02 Mar 2010    2010-03-02
1    MAA NANNA CHIRANJEEVI    833    03 Mar 2010    2010-03-03

No comments:

Post a Comment