We help IT Professionals succeed at work.

Update Column prefixes each value

Shezad Ahmed
Shezad Ahmed asked
on
Medium Priority
237 Views
Last Modified: 2010-04-21
Hi Guys

I have a simple issue and I can't work it out.

I need to write a Microsoft SQL script.

I have a table called Notes.
It includes 2 colums ID AND Note

I would like to go through each note prefixes the note with zz_

Any help highly appreciated

Comment
Watch Question

Database Consultant
CERTIFIED EXPERT
Top Expert 2009
Commented:
are u looking to update all the notes

UPDATE Notes
SET Note = 'zz_' + Note

You can do this in your select

SELECT ID, 'zz_' + Note AS Note
FROM Notes

You may want to include the WHERE if Note can be NULL, please note (no pun intended) that if Note is Null it will return a Null when you do 'zz_' + Note

UPDATE Notes
SET Note = 'zz_' + Note
WHERE Note IS NOT NULL

Cheers, Andrew
CERTIFIED EXPERT
Top Expert 2011

Commented:
sql server database?  (which version ?)

what is the datatype of the notes column?

update Notes
 set Note = 'zz_' + note
 Where substring(Note,1,3) <> 'zz_'


 

Author

Commented:
Thanks.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.