开发者

Update table SQL query help

开发者 https://www.devze.com 2022-12-12 20:27 出处:网络
I have a database student(attribute - studentid). studentid is a varchar. 开发者_运维百科Now I want to add \'P\' at the end of all studentids.

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'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号