I do not know how to resolve this error:
Conversion failed when converting the varchar value
'SELECT LastName,FirstName FROM ##Results WHERE ##RowNum BETWEEN(' to data type int.
Query is:
SET @s_query = 'SELECT ' + @ColNames1 + ' FROM ##Results
WHERE ##RowNum BETWEEN('+@PageIndex1+'-1) * '+@PageSize1+' + 1
AND((('+@PageIndex1+' -1) * '+@PageSize1+' + 1) + '+@PageSize1+') - 1';
To convert a varchar type to a numeric type, change the target type as numeric or BIGNUMERIC as shown in the example below: SELECT CAST('344' AS NUMERIC) AS NUMERIC; SELECT CAST('344' AS BIGNUMERIC) AS big_numeric; The queries above should return the specified value converted to numeric and big numeric.
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
DECLARE @s_query NVARCHAR(MAX);
DECLARE @ColNames1 NVARCHAR(MAX) = 'Some_Column'
DECLARE @PageIndex1 INT = 10;
DECLARE @PageSize1 INT = 20;
SET @s_query = N'SELECT ' + QUOTENAME(@ColNames1) + N' FROM ##Results
WHERE RowNum BETWEEN('+CAST(@PageIndex1 AS NVARCHAR)+ N'-1) * '
+ CAST(@PageSize1 AS NVARCHAR)+ N' + 1 AND((('+ CAST(@PageIndex1 AS NVARCHAR)+ N' -1) * '
+ CAST(@PageSize1 AS NVARCHAR)+ N' + 1) + '+ CAST(@PageSize1 AS NVARCHAR)+ N') - 1';
PRINT @s_query
SELECT [Some_Column] FROM ##Results
WHERE RowNum BETWEEN(10-1) * 20 + 1 AND(((10 -1) * 20 + 1) + 20) - 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With