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.
| Author |
Topic |
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2006-03-27 : 14:12:26
|
| In the following code, it print if print 'Done ' after END, but it doesn't print if print 'Done ' + @ProductID. Why? Is there a step incorrect in the code? I didn't receive error. Thanks.DECLARE @ProductIDFetch as intDECLARE @ProductFetch as varchar(20)DECLARE @ProjectHoursFetch as realDECLARE @ProductID as varchar(5)DECLARE ProductIDCursor CURSOR FORselect top 6 product, intProductID, sum(realProjectHours) as ProjectHours from qryDailytimeview where WeekendingDate = '01/08/2006' and intProductID not in ('0', '1') group by product, intProductID order by ProjectHours descOPEN ProductIDCursorFETCH NEXT FROM ProductIDCursor into @ProductFetch, @ProductIDFetch, @ProjectHoursFetch SET @ProductID = @ProductID + CAST(@ProductIDFetch AS varchar(5))WHILE @@FETCH_STATUS = 0BEGIN SET @ProductID = @ProductID + ',' + CAST(@ProductIDFetch AS varchar(5)) FETCH NEXT FROM ProductIDCursor into @ProductFetch, @ProductIDFetch, @ProjectHoursFetch ENDprint 'Done ' + @ProductIDCLOSE ProductIDCursorDEALLOCATE ProductIDCursorThanks.DanYeungThanks.DanYeung |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-03-27 : 14:49:05
|
| Try initializing @ProductID before using................SET @ProductID = ''OPEN ProductIDCursor............ |
 |
|
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2006-03-27 : 14:53:42
|
| I found out the problem.SET @ProductID = @ProductID + CAST(@ProductIDFetch AS varchar(5)) before WHILE loop should beSET @ProductID = CAST(@ProductIDFetch AS varchar(5))Please disregard my previous post.DanYeungThanks.DanYeung |
 |
|
|
|
|
|