April 2, 2014 at 6:42 pm
Hi Guys
I have a column called ColumnA with the following data in it
2300>MC13
What I need to achieve is copy the last five characters into ColumnB...ie
>MC13
Can someone assist with the correct statement to do this?
Thanks in advance
A
April 2, 2014 at 6:51 pm
Hi,
You can try this
ColumnB = Right(colname, LEN(colname) - 4)
Regards.
April 2, 2014 at 6:54 pm
Do you always want the 5 characters on the right? Or is it always the everything to the right of and including the gt ">" symbol?
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 2, 2014 at 6:59 pm
Hi
Thanks you for the reply
I just need the > symbol and the 4 characters after it
All the data is consistent in character length
A
April 2, 2014 at 7:05 pm
Thank you Kish...your suggestion worked!:-)
April 2, 2014 at 7:22 pm
Here is a means to get that data that allows for some variances - just in case.
DECLARE @table TABLE (ColumnA VARCHAR(20), ColumnB varchar(20))
INSERT INTO @table (ColumnA) VALUES ('2300>MC13')
SELECT SUBSTRING(ColumnA,CHARINDEX('>',ColumnA),LEN(ColumnA)-CHARINDEX('>',ColumnA)+1)
FROM @table
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 2, 2014 at 7:28 pm
Oh and here is the rest of the setup to update ColumnB
DECLARE @table TABLE (ColumnA VARCHAR(20), ColumnB varchar(20))
INSERT INTO @table (ColumnA) VALUES ('2300>MC13');
SELECT SUBSTRING(ColumnA,CHARINDEX('>',ColumnA),LEN(ColumnA)-CHARINDEX('>',ColumnA)+1)
FROM @table;
UPDATE t
SET ColumnB = SUBSTRING(ColumnA,CHARINDEX('>',ColumnA),LEN(ColumnA)-CHARINDEX('>',ColumnA)+1)
FROM @table t;
SELECT *
FROM @table;
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply