I have a table with varchar fields & I need to covert the fields to money
fields. My problem is if the varchar data is of format (581.63) how can I
change that to -581.63 before then doing the convert ie using CAST(July AS
money). Using there CAST function fails because of the brackets.You might try using a CASE expression:
CASE WHEN LEFT(July, 1) = '(' AND RIGHT(July, 1) = ')'
THEN CAST(SUBSTRING(July, 2, LEN(July) - 2) AS money) * -1
ELSE CAST(July AS money) END AS July
Hope this helps.
Dan Guzman
SQL Server MVP
"ChrisB" <ChrisB@.discussions.microsoft.com> wrote in message
news:389EEB22-E89F-413B-823B-5F045C9F3B04@.microsoft.com...
>I have a table with varchar fields & I need to covert the fields to money
> fields. My problem is if the varchar data is of format (581.63) how can I
> change that to -581.63 before then doing the convert ie using CAST(July AS
> money). Using there CAST function fails because of the brackets.
No comments:
Post a Comment