June 18, 2014 at 6:18 pm
Hello all,
I am looking for a script to trim the left side and right of a cell. I can trim either side but not at the same time. Any ideas would help. Trying to trim both sides of column1.
Select right(column1, 37) as new_Column1
from table1
June 18, 2014 at 6:29 pm
Are you looking for LTRIM/RTRIM for whitespace trimming, or some form of SUBSTRING() manipulation to grab the center of actual text? We'll need some more details to help you on this.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
June 18, 2014 at 6:55 pm
I just posted a reply not sure if it went through.
June 18, 2014 at 6:59 pm
Thanks Craig Farrell,
THe column is a (nvarchar(255),null)
The column read as: 'Update record GUID{1231jk-2322yy-2883487-dhe33}'
I can trim the left side giving me the result: '1231jk-2322yy-2883487-dhe33}'
But I need only the GUID: '1231jk-2322yy-2883487-dhe33'
Thanks,
Clarence
June 18, 2014 at 7:03 pm
Like this?
DECLARE @testdata nVARCHAR(255)
SET @testdata = N'Update record GUID{1231jk-2322yy-2883487-dhe33}'
SELECT
SUBSTRING( @testdata, CHARINDEX( '{', @testdata) + 1, CHARINDEX( '}', @testdata) - CHARINDEX( '{', @testdata) - 1)
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
June 18, 2014 at 7:17 pm
Craig,
Will this also work on a column and not just the cell?
June 18, 2014 at 7:28 pm
Replace @testdata with your column name and you should be good to go.
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
June 18, 2014 at 8:19 pm
Yes, I did that but it is still only trimming the GUID that I list in the
SET @ACTIVITY = N'updating records for GUID {121212-12121h-121233-dhf3}'
This is the only result I get back that is trimmed. I would like to apply this on the entire column.
Thanks again for all your help.
June 18, 2014 at 8:33 pm
If you want to know all about the SUBSTRING function, it's covered at http://msdn.microsoft.com/en-us/library/ms187748%28v=sql.100%29.aspx. If you have any questions about it, that's a good page to read.
June 18, 2014 at 9:04 pm
Thanks Ed, that help solved the problem.
Thanks, Clarence
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply