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: Thursday, September 25, 2014 9:51 PM
Points: 173, Visits: 430
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
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Wednesday, September 10, 2014 4:15 AM
Points: 686, Visits: 212
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: Thursday, September 25, 2014 9:51 PM
Points: 173, Visits: 430
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