简体   繁体   English

更新表SQL查询帮助

[英]Update table SQL query help

I have a database student(attribute - studentid). 我有一个数据库student(attribute-studentid)。 studentid is a varchar. studentid是varchar。 Now I want to add 'P' at the end of all studentids. 现在,我想在所有学生证的末尾添加“ P”。

12 -> 12P 234 -> 234P 12-> 12P 234-> 234P

What will be the sql query for this? 这将是什么SQL查询?

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

这适用于SQL Server:

select cast(Studentid as varchar) +'P' from student
update @t
set studentid = studentid + 'P'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM