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)
 how to sum 2 columns

Author  Topic 

andryi
Starting Member

17 Posts

Posted - 2010-02-24 : 11:39:05
hi everybody, I've got a problem
SELECT
substring(A.tanque1,charindex(':',A.tanque1)+1,charindex(')',A.tanque1)-charindex(':',A.tanque1)-1) AS CAPACTIDAD1,
substring(A.tanque2,charindex(':',A.tanque2)+1,charindex(')',A.tanque2)-charindex(':',A.tanque2)-1) AS CAPACTIDAD2,
(cast(CAPACIDAD1 as FLOAT) + cast(CAPACIDAD2 as FLOAT)) AS TOTAL123
from table

and, I want to sum capacidad1 plus capacidad2 so I cast the column to foalt, but nothing work, only have null how result

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 11:42:03
may be this
SELECT CAPACTIDAD1,CAPACTIDAD2,
(COALESCE(cast(CAPACIDAD1 as FLOAT),0) + COALESCE(cast(CAPACIDAD2 as FLOAT),0)) AS TOTAL123
FROM
(
SELECT
substring(A.tanque1,charindex(':',A.tanque1)+1,charindex(')',A.tanque1)-charindex(':',A.tanque1)-1) AS CAPACTIDAD1,
substring(A.tanque2,charindex(':',A.tanque2)+1,charindex(')',A.tanque2)-charindex(':',A.tanque2)-1) AS CAPACTIDAD2
from table
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

andryi
Starting Member

17 Posts

Posted - 2010-02-24 : 12:02:52
thank's for your reply visakh16, It WORKS :D, thank you very much
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-24 : 12:05:35
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

donald1
Starting Member

4 Posts

Posted - 2010-02-24 : 15:59:56
quote:
Originally posted by visakh16

may be this
SELECT CAPACTIDAD1,CAPACTIDAD2,
(COALESCE(cast(CAPACIDAD1 as FLOAT),0) + COALESCE(cast(CAPACIDAD2 as FLOAT),0)) AS TOTAL123
FROM
(
SELECT
substring(A.tanque1,charindex(':',A.tanque1)+1,charindex(')',A.tanque1)-charindex(':',A.tanque1)-1) AS CAPACTIDAD1,
substring(A.tanque2,charindex(':',A.tanque2)+1,charindex(')',A.tanque2)-charindex(':',A.tanque2)-1) AS CAPACTIDAD2
from table
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






i agree with u go ahead with him......correct.

(link removed)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-25 : 09:37:17
quote:
Originally posted by donald1

quote:
Originally posted by visakh16

may be this
SELECT CAPACTIDAD1,CAPACTIDAD2,
(COALESCE(cast(CAPACIDAD1 as FLOAT),0) + COALESCE(cast(CAPACIDAD2 as FLOAT),0)) AS TOTAL123
FROM
(
SELECT
substring(A.tanque1,charindex(':',A.tanque1)+1,charindex(')',A.tanque1)-charindex(':',A.tanque1)-1) AS CAPACTIDAD1,
substring(A.tanque2,charindex(':',A.tanque2)+1,charindex(')',A.tanque2)-charindex(':',A.tanque2)-1) AS CAPACTIDAD2
from table
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






i agree with u go ahead with him......correct.




Are you his manager?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

donald1
Starting Member

4 Posts

Posted - 2010-02-25 : 15:59:32
quote:
Originally posted by visakh16

quote:
Originally posted by donald1

quote:
Originally posted by visakh16

may be this
SELECT CAPACTIDAD1,CAPACTIDAD2,
(COALESCE(cast(CAPACIDAD1 as FLOAT),0) + COALESCE(cast(CAPACIDAD2 as FLOAT),0)) AS TOTAL123
FROM
(
SELECT
substring(A.tanque1,charindex(':',A.tanque1)+1,charindex(')',A.tanque1)-charindex(':',A.tanque1)-1) AS CAPACTIDAD1,
substring(A.tanque2,charindex(':',A.tanque2)+1,charindex(')',A.tanque2)-charindex(':',A.tanque2)-1) AS CAPACTIDAD2
from table
)t


oh...how do u know...very good

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






i agree with u go ahead with him......correct.




Are you his manager?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/







oh really..???...how do u know me.

(link removed)
Go to Top of Page
   

- Advertisement -