Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Script to calculate Precision & Scale of a Decimal Value Expand / Collapse
Author
Message
Posted Tuesday, June 05, 2012 1:14 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 27, 2013 3:34 AM
Points: 165, Visits: 405
Comments posted to this topic are about the item Script to calculate Precision & Scale of a Decimal Value

--In 'thoughts'...
Lonely Rogue
Post #1311438
Posted Tuesday, June 19, 2012 6:54 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, April 08, 2013 10:09 PM
Points: 499, Visits: 147
DECLARE @D DECIMAL(18,9)
,@S VARCHAR(20)
,@R VARCHAR(20)
,@Pos SMALLINT




SET @D = 5.1235698
SET @S = CAST(@D AS VARCHAR(20))
SET @R = REVERSE(SUBSTRING(@S, CHARINDEX('.', @S) + 1, 20))
SET @Pos = PATINDEX('%[1-9]%' , @R)
IF @Pos = 0
SELECT 0
ELSE
SELECT LEN(SUBSTRING(@R, @Pos, 20)) AS Length

Post #1317973
Posted Friday, June 22, 2012 10:35 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, March 27, 2013 3:34 AM
Points: 165, Visits: 405
That is true.. your script evaluates in the same way as mine does. As noted, there exists many approaches that includes yours.

However, the SUBSTRING function along with CHARINDEX seems costlier than the PARSENAME...

Neverthless, thanks for adding this code piece :)



--In 'thoughts'...
Lonely Rogue
Post #1320101
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse