将nvarchar转换为int时转换失败 [英] Conversion failed when converting the nvarchar to int
问题描述
大家好,
我需要找到列名的总和。
i试了使用以下代码,但我收到以下错误,
请给我一个解决方案。
选择'+ sum(cast(@Scolumns as int))+'作为Total FROM #temp_MatchesTotal';
错误消息:
转换nvarchar值时转换失败',ISNULL([2015_April],0)AS [2015_April],ISNULL([2015_August],0)AS [2015_August], ISNULL([2015_July],0)AS [2015_July],ISNULL([2015_June],0)AS [2015_June],ISNULL([2015_May],0)AS [2015_May]'到数据类型int。
提前感谢。
什么我试过了:
将nvarchar转换为int时转换失败
Hi all,
I need to find sum of the column name.
i have tried with the below code but am getting below error,
please drop me a solution for this.
select ' + sum(cast(@Scolumns as int)) + ' as Total FROM #temp_MatchesTotal';
Error msg:
Conversion failed when converting the nvarchar value ',ISNULL([2015_April], 0) AS [2015_April],ISNULL([2015_August], 0) AS [2015_August],ISNULL([2015_July], 0) AS [2015_July],ISNULL([2015_June], 0) AS [2015_June],ISNULL([2015_May], 0) AS [2015_May]' to data type int.
thanks in advance.
What I have tried:
Conversion failed when converting the nvarchar to int
推荐答案
Isn这个错误显而易见吗? @Scolumns变量中有一串T-SQL。这显然无法转换为整数。
Isn't the error obvious? You have a string of T-SQL in your @Scolumns variable. That clearly cannot be converted to an integer.
这篇关于将nvarchar转换为int时转换失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!