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 |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2005-08-22 : 17:19:39
|
| I am keep gettign the converting error meessge when I run below cursor.Server: Msg 245, Level 16, State 1, Line 58Syntax error converting the nvarchar value 'SET ROWCOUNT 1 DELETE IndTest WHERE Site = 'AA009' AND ID = '30587262828||1' AND SALE = '3050276286' AND TDESC = 'AAAAAAAAAAAAAAAAAAAAA' AND TRANS = '' to a column of data type int.-- declare variablesDECLARE @iErrorVar int,@iCount int,@chSite char(5),@vchID varchar(254),@vchSale varchar(50),@vchTDESC varchar(255),@iTrans int,@iTType int,@iTType2 int,@nvchCommand nvarchar(4000),@chCount char(3) -- set initial environmentSET ROWCOUNT 0SET NOCOUNT ON -- Build cursor to find duplicated information DECLARE DelDupe CURSOR FORSELECT COUNT(*) AS Amount,Site,"ID",SALE,TDESC,TRANS,TTYPE,TTYPE2FROM F_POS_LOADwhere SDate >= '06/01/2005' and SDate <= '06/30/2005'GROUP BY Site,"ID",SALE,TDESC,TRANS,TTYPE,TTYPE2HAVING COUNT(*) > 1 OPEN DelDupeprint @icountFETCH NEXT FROM DelDupe INTO @iCount,@chSite,@vchID,@vchSale,@vchTDESC,@iTrans,@iTType,@iTType2 WHILE (@@fetch_status = 0) BEGIN-- Calculate number of rows to delete for each grouping by subtracting-- 1 from the total count for a given group.print @icountSELECT @iCount = @iCount - 1SELECT @chCount = CONVERT(char(3),@iCount)-- now build the rowcount and delete statements.--select char(39)SELECT @nvchCommand = N'SET ROWCOUNT ' + @chCount + ' DELETE IndTest ' + ' WHERE Site = ' + CHAR(39) + @chSite + CHAR(39) +' AND ID = ' + CHAR (39) + @vchID + CHAR(39) +' AND SALE = ' + CHAR (39) + @vchSale + CHAR(39) +--' AND RxScriptNo = ' + CHAR (39) + @vchRxScriptNo + CHAR(39) +' AND TDESC = ' + CHAR (39) + @vchTDESC + CHAR(39) +' AND TRANS = ' + CHAR (39) + @iTrans + CHAR(39) +' AND TTYPE = ' + CHAR (39) + @iTType + CHAR(39) +' AND TTYPE2 = ' + CHAR(39) + @iTType2 + CHAR(39) -- print the statement. For your viewing pleasure only. PRINT @nvchCommand-- execute the statement. --EXEC sp_executesql @nvchCommand SELECT @iErrorVar = @@ErrorIF @iErrorVar <> 0BEGINRETURNEND FETCH NEXT FROM DelDupe INTO @iCount,@chSite,@vchID,@vchSale,@vchTDESC,@iTrans,@iTType,@iTType2 ENDCLOSE DelDupeDEALLOCATE DelDupeRETURN |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-08-22 : 20:15:07
|
| Need to convert some of your variables to character:SELECT @nvchCommand = N'SET ROWCOUNT ' + CONVERT(varchar, @chCount) + ' DELETE IndTest ' + ' WHERE Site = ' + CHAR(39) + @chSite + CHAR(39) +' AND ID = ' + CHAR (39) + @vchID + CHAR(39) +' AND SALE = ' + CHAR (39) + @vchSale + CHAR(39) +--' AND RxScriptNo = ' + CHAR (39) + @vchRxScriptNo + CHAR(39) +' AND TDESC = ' + CHAR (39) + @vchTDESC + CHAR(39) +' AND TRANS = ' + CHAR (39) + CONVERT(varchar, @iTrans) + CHAR(39) +' AND TTYPE = ' + CHAR (39) + CONVERT(varchar, @iTType) + CHAR(39) +' AND TTYPE2 = ' + CHAR(39) + CONVERT(varchar, @iTType2) + CHAR(39) |
 |
|
|
|
|
|
|
|