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.

declare @sqlcommand nvarchar(max);set @sqlcommand = 'this ' + that; exec(@sqlcommand)