Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Increment CASE statement Dynamically

Author  Topic 

skillile
Posting Yak Master

208 Posts

Posted - 2001-11-05 : 09:06:44
--I have this and it is not flexible

SELECT convert(varchar(20),a.sdate, 108),UID,
MIN( CASE b.UID WHEN 1 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 2 THEN b.sdesc END ),
MIN( CASE b.UID WHEN 3 THEN b.sdesc END )
FROM #dayview a
LEFT JOIN #events b ON a.sdate=b.sdate
GROUP BY a.sdate, UID
ORDER BY a.sdate

--I want to do this

DECLARE @count int
DECLARE @x int
SET @x= 1
SET @count=3
DECLARE @sql nvarchar(1000)
WHILE @x <= @count
BEGIN

@sql = @sql + 'MIN( CASE b.UID WHEN ' + @x + 'THEN b.sdesc END )',
@x=@x+1
END


SELECT convert(varchar(20),a.sdate, 108), @sql,
FROM #dayview a
LEFT JOIN #events b ON a.sdate=b.sdate
GROUP BY a.sdate, UID
ORDER BY a.sdate

Not sure how to get there.
Thanks

slow down to move faster...
   

- Advertisement -