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.
| 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 =1Regards,ramu |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-19 : 08:17:06
|
select col2 - col1from yourtable KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ramu143
Yak Posting Veteran
64 Posts |
Posted - 2008-08-19 : 08:21:40
|
hi i have tryed with this syntax i am geting messageInvalid operator for data type. Operator equals subtract, type equals varchar.regardsramuquote: Originally posted by khtan select col2 - col1from yourtable KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
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] |
 |
|
|
ramu143
Yak Posting Veteran
64 Posts |
Posted - 2008-08-19 : 08:31:15
|
hi my data type is varchar... can we do with thisregardsquote: 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]
|
 |
|
|
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] |
 |
|
|
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 thisregardsquote: 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?TrySelect cast(col1 as int)-cast(col2 as int) from tableMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|