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 : 15:09:22
|
| The first part of the following code, the print out is 32 11355 109.539 10514 1026 6515 47Product ID 32,55The last line should be Product ID 32,55,39,14,6,15.What did I miss?I received an error in the second part "Syntax error converting the varchar value '32,55' to a column of data type int." on intProductID not in ( @ProductID ).How should I use @ProductID?DECLARE @ProductIDFetch as intDECLARE @ProjectHoursFetch as realDECLARE @ProductID as varchar(5)DECLARE ProductIDCursor CURSOR FORselect top 6 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 @ProductIDFetch, @ProjectHoursFetch SET @ProductID = CAST(@ProductIDFetch AS varchar(5))WHILE @@FETCH_STATUS = 0BEGIN print CAST(@ProductIDFetch AS varchar(5)) + ' ' + CAST(@ProjectHoursFetch AS varchar(5)) FETCH NEXT FROM ProductIDCursor into @ProductIDFetch, @ProjectHoursFetch SET @ProductID = @ProductID + ',' + CAST(@ProductIDFetch AS varchar(5))ENDCLOSE ProductIDCursorDEALLOCATE ProductIDCursorPRINT 'Product ID ' + @ProductID-----------------------------------------------------------------select 'other', sum(realProjectHours) as ProjectHours from qryDailytimeview where WeekendingDate = '01/08/2006' and intProductID not in ( @ProductID )Thanks.DanYeung |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-03-27 : 15:36:18
|
| DECLARE @ProductID as varchar(1000)That's why it's truncated.You have the statementintProductID not in ( @ProductID )which should be',' + @ProductID + ',' not like '%,' + convert(varchar(20),intProductID) + ',%'==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2006-03-27 : 16:03:17
|
| Thank you so much.Thanks.DanYeung |
 |
|
|
|
|
|
|
|