This may sound silly, and I'm not one to complain when something works, but I just don't get how this one works.
Here's the example someone posted in a blog at sqlteam.com:
What I don't get is that in his real world example, about 3/4 way down the page, he uses values like this:
So what I don't get is how he's able to use REPLACE inside PARSENAME to get to the end result. I know that REPLACE replaces one character or string with another, but what I don't get is how he's able to:
Use a string that already has periods/decimals in it
Replace the colon character with period/decimal
And yet still accurately use PARSENAME
Or does it just happen that the trailing period just gets whacked off? I think that may be what's happening, but not sure. Could anyone glance at this and let me know if I'm being accurate or not?
The reason I'm asking is that if I tried to use this in a real world scenario where I needed to introduce decimals, but I already HAVE decimals in the value, I'd end up messing up the data. Frankly, since much of the data I work with includes dollar amounts, chances are it'll already include decimals.
And all that said, are there any newer/better functions for splitting strings in SQL other than writing your own function?
I did come across this thread where it looks like gmmastros wrote a great function to work with:
Thanks for any thoughts/suggestions.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
Here's the example someone posted in a blog at sqlteam.com:
What I don't get is that in his real world example, about 3/4 way down the page, he uses values like this:
Code:
Create Table OldData (
recordID int,
startDate datetime,
duration char(11)
)
GO
INSERT INTO OldData (recordID, startDate, duration)
VALUES (1, '2002-11-10 12:00:00.000', '4:15:03:24')
INSERT INTO OldData (recordID, startDate, duration)
VALUES (2, '2002-11-10 12:00:00.000', '12:1:23:2')
GO
So what I don't get is how he's able to use REPLACE inside PARSENAME to get to the end result. I know that REPLACE replaces one character or string with another, but what I don't get is how he's able to:
Use a string that already has periods/decimals in it
Replace the colon character with period/decimal
And yet still accurately use PARSENAME
Or does it just happen that the trailing period just gets whacked off? I think that may be what's happening, but not sure. Could anyone glance at this and let me know if I'm being accurate or not?
The reason I'm asking is that if I tried to use this in a real world scenario where I needed to introduce decimals, but I already HAVE decimals in the value, I'd end up messing up the data. Frankly, since much of the data I work with includes dollar amounts, chances are it'll already include decimals.
And all that said, are there any newer/better functions for splitting strings in SQL other than writing your own function?
I did come across this thread where it looks like gmmastros wrote a great function to work with:
Thanks for any thoughts/suggestions.
"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57