April 16, 2009 at 12:53 pm
I need to sum up numeric data from an analysis cube however #miss is shown on the fields with zero data.
[Column 13] is the column on table #temp It was from its original table nvarchar.
I am trying to do a convert to 0.00 but am failing with each syntax I am doing.
CONVERT (decimal(2,2),[Column 13])
or
CONVERT (decimal(2,2),[Column 13],2)
Need some assistance..thanks
April 16, 2009 at 1:16 pm
Your convert function looks fine to me...
I tried this and it worked:
DECLARE @Tmp TABLE ([Column 13] nvarchar(20))
INSERT INTO @Tmp SELECT '0.00'
select CONVERT (decimal(2,2),[Column 13]) from @Tmp
select CONVERT (decimal(2,2),[Column 13],2) from @Tmp
Have you considered using the IsNumeric() function to check whether the data is numerically convertible or not?
April 16, 2009 at 1:21 pm
Hi Rajib,
I did the following query:
SELECT ISNUMERIC(column_13) from #temp
The column brought back 0 and 1s
Again this column that has budget data. So values like 100, 105, 105.67, 9845.43, #MISS appear
I tried to do a SELECT CONVERT(numeric 18,2),column_13) AS convert_col13 INTO #temp2 from #temp but I still get error about unable to convert nvarchar to numeric
April 16, 2009 at 1:22 pm
to convert to 0.00 format you need CONVERT(decimal(3,2),[column 13]) oytherwise you will get a Arithmetic overflow error converting varchar to data type numeric. error. 0,00 is 3 digits long 2 of which are after the decimal place. decimal(2,2) means your answer is 2 digits long of which 2 digits are to the right of the decimal; example .00
Francis
April 16, 2009 at 1:48 pm
Tried that and no dice
SELECT *, CONVERT(decimal(3,2),[Column 13]) AS CONVERT13
INTO #TEMP2 FROM #TEMP
April 16, 2009 at 2:14 pm
If you are getting an error please post it
Francis
April 16, 2009 at 2:21 pm
add the error, your temp table script, insert script, and anything else that gives everyone a clear picture
April 17, 2009 at 6:44 am
jsheldon (4/16/2009)
Hi Rajib,I did the following query:
SELECT ISNUMERIC(column_13) from #temp
The column brought back 0 and 1s
Again this column that has budget data. So values like 100, 105, 105.67, 9845.43, #MISS appear
I tried to do a SELECT CONVERT(numeric 18,2),column_13) AS convert_col13 INTO #temp2 from #temp but I still get error about unable to convert nvarchar to numeric
The bolded item in your list is at least one of the things that is causing the error. You can't convert '#MISS' to a numeric. You could try doing:
SELECT
CONVERT(numeric(18, 2), column_13) AS convert_col13
INTO
#temp2
from
#temp
WHERE -- only do ones that could be numeric.
ISNUMERIC(column_13) = 1
You could still get some errors as currency characters, '-', and '.' are among characters that cause isnumeric to return 1.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
April 17, 2009 at 7:22 am
try using a CASE statement like
SELECT column_13
, CASE ISNUMERIC(column_13)
WHEN 1 THEN CONVERT(numeric(18,2),column_13)
ELSE 0.00
END
FROM #temp
Francis
April 20, 2009 at 8:10 am
Francis,
Your code was the best fit...thanks to all for the help...
April 22, 2009 at 1:53 pm
jsheldon (4/20/2009)
Francis,Your code was the best fit...thanks to all for the help...
Just don't rely on ISNUMERIC being some sort of magical ISALLDIGITS function because it's not. Please see the following thread for all the reasons why not. Frank Kalis and I spent a bit of time at it....
http://www.sqlservercentral.com/Forums/Topic243646-8-1.aspx?Highlight=ISALLDIGITS
--Jeff Moden
Change is inevitable... Change for the better is not.
April 22, 2009 at 2:31 pm
Well thats annoying. Although I (only sort of) accept the E notation being accepted. Anyway the referenced discussion was a interesting read. Thanks for pointing that out.
Francis
April 11, 2012 at 2:53 pm
Just wanted to say THANK YOU! this issue was making me crazy.....
December 17, 2014 at 8:00 am
Hi,
I have exactly the same issue, and the found that solution perfect but it still getting error.
My question is: how could I find the row producing error? I am selecting only ISNUMERIC([column]) = 1 however, get the error:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.
December 17, 2014 at 9:26 am
ichv (12/17/2014)
Hi,I have exactly the same issue, and the found that solution perfect but it still getting error.
My question is: how could I find the row producing error? I am selecting only ISNUMERIC([column]) = 1 however, get the error:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.
Did you read the article mentioned?
What version of SQL are you using?
Can you post the query that you're using (the relevant parts)?
Viewing 15 posts - 1 through 15 (of 16 total)
You must be logged in to reply to this topic. Login to reply