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 |
|
osupratt
Posting Yak Master
238 Posts |
Posted - 2008-07-11 : 12:05:04
|
| I'm having an issue with the following CASE statement:WHEN MAX(SalesPerMonth)=0 AND MAX(Available)>0 AND MAX(TurnRatio) =0 THEN 'infinity'ELSE MAX(Available)/MAX(SalesPerMonth)END AS MonthsSupplyOnHandThis comes back with 'Error converting data type varchar to float'.Any help would be appreciated. Thanks. |
|
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-07-11 : 12:19:59
|
| caseWHEN MAX(SalesPerMonth)=0 AND MAX(Available)>0 AND MAX(TurnRatio) =0 THEN 'infinity'ELSE Cast(MAX(Available)/MAX(SalesPerMonth) as varchar) END AS MonthsSupplyOnHand"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-11 : 13:06:55
|
WHEN MAX(SalesPerMonth)=0 AND MAX(Available)>0 AND MAX(TurnRatio) =0 THEN 'infinity'ELSE str(1.0 * MAX(Available) / MAX(SalesPerMonth), 12, 2) END AS MonthsSupplyOnHand E 12°55'05.25"N 56°04'39.16" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-12 : 00:56:06
|
| Make sure all values returned from CASE construct are of same datatype. the above error because you're trying to return string value in one condition and float in another. |
 |
|
|
|
|
|