Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cvipin
Yak Posting Veteran

USA
51 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

3873 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  
 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.02 seconds. Powered By: Snitz Forums 2000