Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Is there a quick way to achieve following in select statement:00000000403.50- --> -403.5000000000403.50+ --> 403.50ThanksVipin
James K
Master Smack Fu Yak Hacker
3873 Posts
Posted - 2013-04-08 : 14:59:12
Could possibly be done more cleverly than the query below, but if you always have a + or - at the end, this should work:
DECLARE @X VARCHAR(32) = '00000000403.50-';SELECT CAST(STUFF(@X,PATINDEX('%[+-]',@X),1,'') AS DECIMAL(19,2)) *CASE WHEN @X LIKE '%-' THEN -1 ELSE 1 END