Author |
Topic |
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-24 : 10:12:54
|
Hi, I am running this code :-select temp16.*,(Pasea_Cost_Price/NULLIF(UNIT_CASE,0)) as Pasea_CP_Modified from temp16 Now , I am seeing NULL values in Pasea_CP_Modified,I want to see a 0 in place of a NULL value.How to do tht??Regards,SushantDBAVirgin Islands(U.K) |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-02-24 : 10:13:53
|
[code]ISNULL((Pasea_Cost_Price/NULLIF(UNIT_CASE,0)), 0) AS [Pasea_CP_Modified][/code]Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-24 : 10:20:46
|
Cool, that was easy and fast !Regards,SushantDBAVirgin Islands(U.K) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2012-02-24 : 11:57:31
|
quote: Originally posted by X002548 UNIT_CASE*1.00 Brett
Why this UNIT_CASE*1.00 ??Regards,SushantDBAVirgin Islands(U.K) |
 |
|
X002548
Not Just a Number
15586 Posts |
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2012-02-24 : 13:59:58
|
he's saying that if UNIT_CASE is and integer type (smallint / bigint / int) then you'll get integer division which may not be what you want.If UNIT_CASE is a DECIMAL/NUMERIC (same thing) or a FLOAT TYPE (or even a money type) then you'll get 'standard' division.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-24 : 14:42:29
|
Just to clarify, if both the numerator and denominator are of an integer type, sql will provide the result as an integer type (thus no decimal places). If, either the numerator or denominator are of a decimal type, then the result will be based on the sql rules for converstion and such, but you (should) get a decimal result.In this case, assuming that Pasea_Cost_Price is not an integer type, you should not need to multiply by 1.00. I'd also go so far to suggest not properly casting your data is bad form anyway, but that's a whole other topic. |
 |
|
|