April 21, 2005 at 10:18 am
Need T-SQL to append the character "@" onto the end of all Column values (column: SupplyName nvarchar(32))
Example: I'd like the following SOURCE sample values converted to the TARGET values:
SOURCE TARGET
Abc Abc@
Xyzzz Xyzzz@
123abc 123abc@
Bob Cat Bob Cat@
Thx in advance!
April 21, 2005 at 10:24 am
For a one time run:
UPDATE TableName SET Target = Source + '@'
For multiple runs:
UPDATE TableName SET Target = Source + '@' WHERE RIGHT(Target,1) '@'
That way you only are touching the new records.
----------------
Jim P.
A little bit of this and a little byte of that can cause bloatware.
April 21, 2005 at 11:43 am
You can also take in consideration that this operation can be done at the select level (if you're not sure you want to alter the underlying data).
April 22, 2005 at 1:11 am
April 22, 2005 at 6:23 am
Good point. I just took the obvious.
----------------
Jim P.
A little bit of this and a little byte of that can cause bloatware.
April 22, 2005 at 7:02 am
Also bear in mind that LEN ignores trailing spaces and if the column was padded with spaces then the concatenation may not work. This is probably not the case here but you never know
Far away is close at hand in the images of elsewhere.
Anon.
April 22, 2005 at 7:13 am
Okay - to cover every realm of possibility :
UPDATE TableName SET SupplyName = LTRIM(RTRIM(SupplyName)) + '@' WHERE RIGHT(SupplyName,1) '@' AND LEN(SupplyName) < 32
Now, is there anything else we forgot about this simple update query?
----------------
Jim P.
A little bit of this and a little byte of that can cause bloatware.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply