gpt4 book ai didi

sql-server - 在 SQL Server 2008 中将 varchar 值转换为数据类型 int 时转换失败

转载 作者:行者123 更新时间:2023-12-02 14:46:40 25 4
gpt4 key购买 nike

我不知道如何解决此错误:

Conversion failed when converting the varchar value
'SELECT LastName,FirstName FROM ##Results WHERE ##RowNum BETWEEN(' to data type int.

查询是:

SET @s_query = 'SELECT ' + @ColNames1 + ' FROM ##Results
WHERE ##RowNum BETWEEN('+@PageIndex1+'-1) * '+@PageSize1+' + 1
AND((('+@PageIndex1+' -1) * '+@PageSize1+' + 1) + '+@PageSize1+') - 1';

最佳答案

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

关于sql-server - 在 SQL Server 2008 中将 varchar 值转换为数据类型 int 时转换失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21906781/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com