January 12, 2010 at 9:45 am
Hello
I have a field that contains data in below format
{FFFFFFFF-0000-0000-0000-000000000463}
{FFFFFFFF-0000-0000-0000-000000000463}
{FFFFFFFF-0000-0000-0000-000000000463}
{FFFFFFFF-0000-0000-0000-000000001576}
{FFFFFFFF-0000-0000-0000-000000001576}
{FFFFFFFF-0000-0000-0000-000000000606}
{FFFFFFFF-0000-0000-0000-000000000850}
{FFFFFFFF-0000-0000-0000-000000000850}
{FFFFFFFF-0000-0000-0000-000000001576}
and i would like to strip { and } from begining and end of the string and store the data.
How can i do this in a query?
Thanks
January 12, 2010 at 9:50 am
DECLARE @test-2 varchar(50)
SET @test-2 = '{FFFFFFFF-0000-0000-0000-000000000463}'
PRINT REPLACE(REPLACE(@test, '{', ''), '}', '')
PRINT SubString(@test, 2, len(@test)-2)
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
January 12, 2010 at 9:52 am
Are talking about stripping the { and } from the data and replacing it in the same place?
January 12, 2010 at 10:04 am
January 12, 2010 at 10:15 am
I would try the two methods below and check which one runs faster.
If the length of your data will always be the same then you might not need to use then LEN function, which probably makes the last statement the fastest [edit] of the three solutions below[/edit]...
declare @x varchar(50)
SET @x='{FFFFFFFF-0000-0000-0000-000000000463}'
SELECT replace(replace(@x,'{',''),'}','')
SELECT substring(@x,2,len(@x)-2)
SELECT substring(@x,2,36)
January 12, 2010 at 10:29 am
January 12, 2010 at 11:05 am
You're definitely right...
Should have limited "fastest" to the solutions provided in the post.
I'll go and edit it... 😉
January 12, 2010 at 12:32 pm
below did it
update dbo.testtable set testcode = substring(testcode,1,len(testcode)-1)
Thanks
January 12, 2010 at 12:53 pm
Armani (1/12/2010)
below did itupdate dbo.testtable set testcode = substring(testcode,1,len(testcode)-1)
Thanks
That's really strange...
Your query only removes the last character, but not the first one:
declare @x varchar(50)
SET @x='{FFFFFFFF-0000-0000-0000-000000000463}'
SELECT substring(@x,1,len(@x)-1) --{FFFFFFFF-0000-0000-0000-000000000463
SELECT substring(@x,2,len(@x)-2) --FFFFFFFF-0000-0000-0000-000000000463
But if it's working for you, then it's just fine...
January 12, 2010 at 3:26 pm
How odd. :hehe:
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply