首先祝大家新年快乐.我在编写查询时遇到问题.执行查询时出现错误.
First of all Wish u all Happy New Year. I have a problem in writing query. While executing my query I am getting an error.
查询:
select case
when S.R1 = '6' then 5
when S.R1 = '7' then 6
when S.R1 = '8' then 7
when S.R1 = '9' then 8
when S.R1 ='10' then 9
else S.R1 end as Q
FROM [HelpService].[dbo].[help] s
-----------------------------------------------
SELECT [Source], [Score]
INTO #Temp_Q
FROM [HelpDesk].[dbo].[Survey]
WHERE [data_Source Name] = 'Text Data'
-----------------------------------------------
select CONVERT(REAL, a.[Dell Score]) as Q
FROM [HelpService].[dbo].[help] s
LEFT OUTER JOIN #CE_Temp_Q a on
s.[R1] = a.[Source]
错误
消息 8114,级别 16,状态 5,第 1 行
Msg 8114, Level 16, State 5, Line 1
将数据类型 varchar 转换为 real 时出错.
Error converting data type varchar to real.
我被要求做的是我需要删除硬编码值并需要使用临时表编写查询.
What I am asked to do is I need to remove the hard coded values and need to write queries with a temp table.
提前致谢,夏什拉
将数据类型 varchar 转换为 real 时出错
Error converting data type varchar to real
这意味着您的一个值包含一些不是数字的东西.
This means one of your values contains somthing that isn't a Number.
例如以下工作正常
SELECT convert(Real, '1')
UNION SELECT convert(Real, ' ')
UNION SELECT convert(Real, NULL)
UNION SELECT convert(Real, '123.123')
UNION SELECT convert(Real, ' 456 ')
但是以下任何一项都会产生与您相同的错误
But either of the following will yield the same error you are getting
SELECT convert(Real, ' 456 ')
SELECT CONVERT(Real, '1 2')
更新
有时问题值是什么并不那么明显
Sometimes its not so obvious what the problem values are
尝试以下方法找到它
SELECT DISTINCT
a.[Dell Score]
FROM
[HelpService].[dbo].[help] s
LEFT OUTER JOIN #CE_Temp_Q a on
s.[R1] = a.[Source]
或
SELECT DISTINCT
a.[Dell Score],
DATALENGTH (a.[Dell Score])
FROM
[HelpService].[dbo].[help] s
LEFT OUTER JOIN #CE_Temp_Q a on
s.[R1] = a.[Source]
这篇关于使用临时表删除硬编码值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合