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 |
|
clement.store
Starting Member
25 Posts |
Posted - 2009-02-18 : 01:16:10
|
| Hello there,Why would casting be needed when i checked that casting from varchar to numeric is implicit in SQL server 2005? And i had to use casting for subtraction as below.SELECT UfCodeTo, UfCodeFrom, CAST(UfCodeTo AS numeric) - CAST(UfCodeFrom AS numeric) AS Expr1FROM code_mapORDER BY Expr1 DESCWhy can't I directly use UfCodeTo - UfCodeFrom? Would anyone have some clues...?ThanksClement |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-02-18 : 02:09:15
|
The real question is why you store codes as varchar, when you later want to do some arithmetic on them... E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-18 : 02:25:20
|
| u can't use the subtract between two varchar fields u will get error as Operand data type varchar is invalid for subtract operator.so that u have to cast or convert ur fields in to numeric or decimalAS peso said store the fields in numeric if there is any some arithmetic on them |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-02-18 : 04:48:05
|
| <<when i checked that casting from varchar to numeric is implicit in SQL server 2005? >>Nodeclare @v1 varchar(10),@v2 varchar(10)select @v1='7652.43',@v2='7123.55'select @v1-@v2MadhivananFailing to plan is Planning to fail |
 |
|
|
clement.store
Starting Member
25 Posts |
Posted - 2009-02-18 : 20:19:46
|
| Thanks! I got it! |
 |
|
|
|
|
|