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
 General SQL Server Forums
 New to SQL Server Programming
 Help me in subtraction

Author  Topic 

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-08-19 : 08:10:36
Hi all,

I am want to subtract the two columns


ex:- 2-1 =1

Regards,
ramu

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-19 : 08:17:06
select col2 - col1
from yourtable


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-08-19 : 08:21:40
hi

i have tryed with this syntax i am geting message
Invalid operator for data type. Operator equals subtract, type equals varchar.
regards
ramu
quote:
Originally posted by khtan

select col2 - col1
from yourtable


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-19 : 08:24:16
you can subtract from varchar column. What are you trying to do ?

Post some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ramu143
Yak Posting Veteran

64 Posts

Posted - 2008-08-19 : 08:31:15
hi
my data type is varchar... can we do with this

regards

quote:
Originally posted by khtan

you can subtract from varchar column. What are you trying to do ?

Post some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-19 : 08:33:02
please explain how do you want to subtract 2 varchar ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-19 : 08:34:33
quote:
Originally posted by ramu143

hi
my data type is varchar... can we do with this

regards

quote:
Originally posted by khtan

you can subtract from varchar column. What are you trying to do ?

Post some sample data and the expected result


KH
[spoiler]Time is always against us[/spoiler]






Why did you use varchar datatype to store numbers?

Try

Select cast(col1 as int)-cast(col2 as int) from table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -