I have a database student(attribute - studentid). studentid is a varchar. 开发者_运维百科Now I want to add 'P' at the end of all studentids.
12 -> 12P 234 -> 234P
What will be the sql query for this?
UPDATE mytable
SET student_id = student_id + 'P' --assumes already varchar
WHERE RIGHT(student_id, 1) <> 'P' --to stop having PP at end...
UPDATE mytable SET student_id=CONCAT(student_id,'P');//mysql
This is for SQL Server:
select cast(Studentid as varchar) +'P' from student
update @t
set studentid = studentid + 'P'
精彩评论