September 3, 2012 at 3:08 am
Basically what I am trying to achieve is to update the last two character spaces of a column which is defined as varchar(40),
my update statement looks like this
UPDATE Vehicle SET Version = 'fiesta zetec 1.2 BT' WHERE unitnr = '140'
Instead of this statement, I am looking for a way of appending the letters 'BT' to the end of the version column. Is there an easy way of doing this?
September 3, 2012 at 3:16 am
Simply do a string concatination on the existing version value.
update vehicle set version = version + ' BT' where unitnr = '140'
September 3, 2012 at 3:16 am
September 3, 2012 at 3:39 am
thomasrichardson2000 (9/3/2012)
Basically what I am trying to achieve is to update the last two character spaces of a column which is defined as varchar(40),my update statement looks like this
UPDATE Vehicle SET Version = 'fiesta zetec 1.2 BT' WHERE unitnr = '140'
Instead of this statement, I am looking for a way of appending the letters 'BT' to the end of the version column. Is there an easy way of doing this?
If did not get the answer, please elaborate with example.
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
π
September 3, 2012 at 4:36 am
Thanks so far, I will clarify further. The requirement is that i update the version field with the letters 'BT' at the end, So if the column is defined as varchar(40) they want the letters 'BT' to be the last 2 characters in the field, so If varchar(40) has space for 40 characters they want 'BT' to be character 39 and 40. I hope this makes sense.
September 3, 2012 at 5:41 am
thomasrichardson2000 (9/3/2012)
Thanks so far, I will clarify further. The requirement is that i update the version field with the letters 'BT' at the end, So if the column is defined as varchar(40) they want the letters 'BT' to be the last 2 characters in the field, so If varchar(40) has space for 40 characters they want 'BT' to be character 39 and 40. I hope this makes sense.
Try this
DECLARE @Version char(40)
SET @Version = 'fiesta zetec 1.2';
SET @Version =SUBSTRING(@Version,1,38) + 'BT';
SELECT @Version
--rhythmk
------------------------------------------------------------------
To post your question use below link
https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
π
September 3, 2012 at 6:07 am
thomasrichardson2000 (9/3/2012)
Thanks so far, I will clarify further. The requirement is that i update the version field with the letters 'BT' at the end, So if the column is defined as varchar(40) they want the letters 'BT' to be the last 2 characters in the field, so If varchar(40) has space for 40 characters they want 'BT' to be character 39 and 40. I hope this makes sense.
Maintaining datatype of @Version:
DECLARE @Version Varchar(40)
SET @Version = 'fiesta zetec 1.2';
SET @Version = LEFT(@Version + SPACE(40),38) + 'BT';
SELECT @Version;
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply