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 5, 2012 1:14 PM


SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Friday, December 20, 2013 3:29 PM
Points: 167, Visits: 407
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
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Today @ 12:30 AM
Points: 641, Visits: 193
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: Friday, December 20, 2013 3:29 PM
Points: 167, Visits: 407
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