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 |
manibad
Starting Member
9 Posts |
Posted - 2012-09-20 : 17:24:08
|
When i use the below query IN temp.salary column i have a value like 120098.33,51234.54select Substring(convert(varchar,temp.salary,102),-2,LEN(convert(varchar,temp.salary,102))) from tempi end up like this120,09851,234Whereas when i use the same query like this select Substring(convert(varchar,120098.33,102),-2,LEN(convert(varchar,120098.33,102)))120098Why does it happen so?PLease explain me this. |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-09-20 : 18:09:50
|
What is the datatype for Salary? Is it Money? If so, the select from TEMP is converting a MONEY to a VARCHAR. THe style makes no sense, so I guess that it is using a style of 1 instead of 0..? The second example is converting from a Float/Decimal to varchar. That has different rules that Money, hence the difference. As an example:SELECT convert(varchar,'120098.33',102)SELECT convert(varchar,120098.33,102)SELECT convert(varchar,CAST(120098.33 AS MONEY),102)SELECT convert(varchar,$120098.33,102) |
 |
|
|
|
|
|
|