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)
 Fetch and print

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 int
DECLARE @ProductFetch as varchar(20)
DECLARE @ProjectHoursFetch as real
DECLARE @ProductID as varchar(5)
DECLARE ProductIDCursor CURSOR FOR
select 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 desc
OPEN ProductIDCursor
FETCH NEXT FROM ProductIDCursor into @ProductFetch, @ProductIDFetch, @ProjectHoursFetch
SET @ProductID = @ProductID + CAST(@ProductIDFetch AS varchar(5))
WHILE @@FETCH_STATUS = 0
BEGIN
SET @ProductID = @ProductID + ',' + CAST(@ProductIDFetch AS varchar(5))
FETCH NEXT FROM ProductIDCursor into @ProductFetch, @ProductIDFetch, @ProjectHoursFetch
END
print 'Done ' + @ProductID
CLOSE ProductIDCursor
DEALLOCATE ProductIDCursor

Thanks.

DanYeung

Thanks.
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
............
Go to Top of Page

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 be
SET @ProductID = CAST(@ProductIDFetch AS varchar(5))

Please disregard my previous post.

DanYeung



Thanks.
DanYeung
Go to Top of Page
   

- Advertisement -