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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problem with CAST

Author  Topic 

Gerten_Utv
Starting Member

7 Posts

Posted - 2009-02-04 : 13:20:28
I have to Convert this to DECIMAL, but get error:
Msg 8152, Level 16, State 2, Line 1
String or binary data would be truncated.
The statement has been terminated.

CAST(Case When MatchResultRoundResult1 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult2 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult3 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult4 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult5 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult6 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult7 > 0 THEN 1 ELSE 0 END +
Case When MatchResultRoundResult8 > 0 THEN 1 ELSE 0 END
AS DECIMAL(10,2)) AS Rounds

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-02-04 : 18:00:02
Whatever you have mentioned should work fine. Are you sure this is where the error is? Can you let know what MatchResultRoundResult1,2,3 will actually hold
Go to Top of Page

AvanthaSiriwardana
Yak Posting Veteran

78 Posts

Posted - 2009-02-04 : 22:13:36
What is your data type ?

Avantha Siriwardana
Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-02-04 : 23:57:30
use like this
Case When ( MatchResultRoundResult1 > 0 and MatchResultRoundResult2 > 0
MatchResultRoundResult3 > 0 and MatchResultRoundResult4 > 0
MatchResultRoundResult5 > 0 and MatchResultRoundResult6 > 0
MatchResultRoundResult7 > 0 and MatchResultRoundResult8 > 0 ) THEN 1.0 ELSE 0.0 END AS Rounds
Go to Top of Page
   

- Advertisement -