0

I have the following query returns resulting me Null or Zero:

SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp 
WHERE ID = 123250838

but when I add a condition asking if the column value is zero causes overflow error:

SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp 
WHERE ID = 123250838
AND [jul-12] <> 0

The data type of the column is FLOAT

exec sp_help 'Table_tmp'
jun-12  float   no  8   53      NULL    yes (n/a)   (n/a)   NULL

I tried with the functions CONVERT () and CAST () but with the same result.

But when the value of the column [Jul-12] is nonzero, it works without errors. Why does this happen?

2
  • Can you build a sample Fiddle -- not experiencing the same problem on my end. This can get you started: sqlfiddle.com/#!3/5029c/1 Commented Feb 8, 2013 at 15:52
  • The temporary table is created through an excel file dump Commented Feb 8, 2013 at 16:00

3 Answers 3

1

Try like below... may be it will help you...

SELECT TOP 1 ISNULL([jul-12],0) FROM Table_tmp 
WHERE  Str([jul-12], 25, 5) <> '0'
Sign up to request clarification or add additional context in comments.

Comments

0

This is because of CAST () specification. The result data type will be as in the second parameter. To avoid this you can use COALESCE function which determine result data type by first parameter, also benefit of this function is that it's ANSI standard (instead of ISNULL). you can look for this function here: COALESCE MSDN usage in your case is: COALESCE(jul-12],0) - this will return first not null value.

Comments

0

I just ran across this problem and solved it by throwing an "IS NOT NULL" clause into "WHERE" on the column that I was using cast()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.