|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 12:27 PM
Points: 15,
Visits: 74
|
|
| I have output for scores that have 2 decimal places (all zeros). I need to remove the decimal places and return a 4 character number in int format. Example: 65.00 must return as 0065; 108.00 must return as 0108. Can anyone help?
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 8:37 AM
Points: 1,607,
Visits: 1,095
|
|
| SELECT RIGHT('000'+CAST(CAST(MyField AS INT) AS VARCHAR(4)),4) should do the trick
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, March 26, 2013 12:27 PM
Points: 15,
Visits: 74
|
|
| That worked perfectly. Thank you!
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, August 05, 2011 8:06 AM
Points: 4,
Visits: 15
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 11:22 AM
Points: 2,541,
Visits: 4,370
|
|
SELECT RIGHT('000'+CAST(CAST(MyField * 100.0 AS INT) AS VARCHAR(4)),4)
_____________________________________________ "The only true wisdom is in knowing you know nothing" "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!" (So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, October 22, 2012 10:17 AM
Points: 3,
Visits: 6
|
|
What happens if you have digits to right of decimal? declare @value3 integer @value3 = 197.81 SELECT RIGHT('000'+CAST(CAST(@value3 AS INT) AS VARCHAR(7)),7)
gives value 000197
any help on this would be appreciated.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 1:55 PM
Points: 15,442,
Visits: 9,571
|
|
stimetb (10/17/2012) What happens if you have digits to right of decimal? declare @value3 integer @value3 = 197.81 SELECT RIGHT('000'+CAST(CAST(@value3 AS INT) AS VARCHAR(7)),7)
gives value 000197
any help on this would be appreciated.
Do you want to keep the decimal values? If so, declare the variable as something that will do what you need, then don't cast it to Int inside the string function.
Declaring the variable as Int drops the decimal value before you even begin formatting it.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, October 22, 2012 10:17 AM
Points: 3,
Visits: 6
|
|
just realized that - i switched it over to money and am working with it thanks
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Today @ 3:20 AM
Points: 2,341,
Visits: 3,175
|
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Monday, October 22, 2012 10:17 AM
Points: 3,
Visits: 6
|
|
Now i have a field that is getting populated from 2 other fields based on which was in not null. We removed decimal point and 0 front filled it. This is what I'm currently doing: (CASE WHEN edm.Percentage IS NULL THEN (ISNULL(RIGHT ('00000000' + CONVERT (varchar (7), FLOOR (ABS (ROUND(edm.amount,2) * 100.0))),7),0)) else (ISNULL(RIGHT ('00000000' + CONVERT (varchar (7), FLOOR (ABS (ROUND(edm.Percentage,2) * 100.0))),7),0)) end)
inside a select statement, We are inputting this data in a card that will split this field up. first 2 bytes go on 1 card and next 5 bytes go on 2nd card
i tried A SCALAR value. but the problem i had was it gave me a constant on the field because i assigned it outside of the insert/select statement and wasnt sure how to do it inside the statement.
|
|
|
|