Problem in removing hardcoded values using temp table
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.
Query:
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'
-----------------------------------------------
开发者_JAVA百科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]
ERROR
Msg 8114, Level 16, State 5, Line 1
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.
Thanks in Advance, Shashra
Error converting data type varchar to real
This means one of your values contains somthing that isn't a Number.
For example the following works fine
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')
UPDATE
Sometimes its not so obvious what the problem values are
Try the following to find it
SELECT DISTINCT
a.[Dell Score]
FROM
[HelpService].[dbo].[help] s
LEFT OUTER JOIN #CE_Temp_Q a on
s.[R1] = a.[Source]
OR
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]
What does the following query return?
select a.[Dell Score]
FROM [HelpService].[dbo].[help] s
LEFT OUTER JOIN #CE_Temp_Q a on
s.[R1] = a.[Source]
WHERE a.[Dell Score] like '%[^0-9.]%'
精彩评论