Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Convert NULL as float

Author  Topic 

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-08-05 : 04:40:27
How to Convert Null to Float in SQL Server 2005.For Eaxmple
July Aug
---- ---
215 Null

How to add these two values but data type is float.


V.NAGARAJAN

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-08-05 : 05:00:06
NULL Refers NOTHING
You may store NULL in any datatype.

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-08-05 : 05:03:09
Hi Vaibav,

i want sql statement.no need suggestion or explanation

V.NAGARAJAN
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-08-05 : 05:05:02
Do you have July Aug Sep Oct & so on as columns ???



Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-05 : 05:09:33
SELECT CONVERT(float, NULL) AS MyColumnName

will give you a NULL in a Float datatype.

Might help if you explain the underlying problem you are trying to solve though.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-08-05 : 05:16:58
quote:
Originally posted by Kristen

SELECT CONVERT(float, NULL) AS MyColumnName

will give you a NULL in a Float datatype.

Might help if you explain the underlying problem you are trying to solve though.



I think he needs addition of July+Aug & the resultset be saved in float datatype.


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-08-05 : 05:18:02
quote:
Originally posted by itnagaraj

Hi Vaibav,

i want sql statement.no need suggestion or explanation

V.NAGARAJAN



Please dont make us try for spoon feeding
Whats wrong with that ?
Why need to convert ?

INSERT INTO YourTable(July, Aug) VALUES(215,NULL)

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-08-05 : 05:23:59
I Wrote SQL for Select Query:

Select Jul,Aug,(Jul+Aug) As Total From Commodity.Pls Modify and reply it

I want result for the following format

Jul Aug Total
215 NULL 215

V.NAGARAJAN
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-08-05 : 05:28:28
quote:
Originally posted by itnagaraj

I Wrote SQL for Select Query:

Select Jul,Aug,(Jul+Aug) As Total From Commodity.Pls Modify and reply it

I want result for the following format

Jul Aug Total
215 NULL 215

V.NAGARAJAN



Select Jul,Aug,Convert(float,(IsNULL(Jul,0)+IsNULL(Aug,0))) As Total From Commodity


Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-05 : 05:40:33
If the columns [Jul] and [Aug] are already FLOAT datatype then no need for the CONVERT. Just use IsNull() or, my preference, COALESCE() to convert any NULL values to 0

Select Jul, Aug, COALESCE(Jul, 0.0) + COALESCE(Aug, 0.0) As Total From Commodity
Go to Top of Page
   

- Advertisement -