SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Convert string to decimal
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cvipin
Starting Member

USA
45 Posts

Posted - 04/08/2013 :  14:47:47  Show Profile  Reply with Quote
Is there a quick way to achieve following in select statement:

00000000403.50- --> -403.50
00000000403.50+ --> 403.50

Thanks
Vipin

James K
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 04/08/2013 :  14:59:12  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000