Reputation: 369
I'm writing a dynamic query for paging purpose. below is the last part of the executable query and when i print it and run in different window it works fine. but when i use exec it shows red squiggle for casting parts (CAST(@pint_StartRowIndex AS VARCHAR)) as showing in attached image.
could anyone tell me why I'm getting this error? If i use Print instead of Exec it gives no errors and printed query execute with no errors.
Upvotes: 0
Views: 60
Reputation: 729
try like this :
exec ('SELECT * from table where Rank BETWEEN CAST ('+ @start + 'as nvarchar)' + ' AND cast (' + @end + 'as nvarchar)')
quote everything as string except @start and @end
Upvotes: 1