I have the below transaction:
DECLARE @strsql1 NVARCHAR(MAX);
DECLARE @rows INT, @count INT;
DECLARE @MySource NVARCHAR(30);
DECLARE @Myfield NVARCHAR(30);
SET @rows = 1;
SET @count = 0;
SELECT @strsql1 =
'WHILE ('+@rows+')> 0
BEGIN
BEGIN TRAN
delete top (10000) from '+@MySource+'
where' +@Myfield+' =''value''
SET '+@rows+' ='+ @@ROWCOUNT+'
SET '+ @count+' = '+ @count+ @rows +'
RAISERROR(''COUNT %d'', 0, 1, '+ @count+') WITH NOWAIT
COMMIT TRAN
END;'
PRINT @strsql1
EXEC sp_executeSql @strSql1
but I get this error message:
Conversion failed when converting the varchar value ' WHILE (' to data type int.
I have try to use the cast with the two variables (@count and @row) but the problem reside.
Could you please suggest some solution?
Thank you.