Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新表SQL查询帮助_Sql_Sql Server_Sql Server 2005_Tsql - Fatal编程技术网

更新表SQL查询帮助

更新表SQL查询帮助,sql,sql-server,sql-server-2005,tsql,Sql,Sql Server,Sql Server 2005,Tsql,我有一个数据库student(属性-studentid)。studentid是一个varchar。现在我想在所有学生的末尾加上“P” 12->12P 234->234P 对此的sql查询是什么?这是针对sql Server的: select cast(Studentid as varchar) +'P' from student 这是针对SQL Server的: select cast(Studentid as varchar) +'P' from student 更新mytable SET

我有一个数据库student(属性-studentid)。studentid是一个varchar。现在我想在所有学生的末尾加上“P”

12->12P 234->234P


对此的sql查询是什么?

这是针对sql Server的:

select cast(Studentid as varchar) +'P' from student

这是针对SQL Server的:

select cast(Studentid as varchar) +'P' from student
更新mytable
SET student\u id=student\u id+'P'--假定已存在varchar
其中右键(学生id,1)“P”-结束时停止使用PP。。。
更新我的表格
SET student\u id=student\u id+'P'--假定已存在varchar
其中右键(学生id,1)“P”-结束时停止使用PP。。。

要将P添加到数据库中的值中,还是在返回值时添加?如果要更新studentid列中的值,是否已将其更新为字符串而不是int类型?请发布当前表定义(即
CREATE table
语句)和所用RDBMS的品牌。任何答案都将取决于此信息。studentid是一个varchar…我的错..我正在使用SQL server 2005..我想向数据库中的值添加P是否要向数据库中的值添加P,或者在返回值时添加P?如果要更新studentid列中的值,是否已将其更新为字符串而不是int类型?请发布当前表定义(即
CREATE table
语句)和所用RDBMS的品牌。任何答案都将取决于此信息。studentid是一个varchar…我的错..我使用的是SQL server 2005..我想将P添加到数据库中的值使用Where条件停止“PP”是非常明智的。这是一种避免将来不必要错误的方法。使用Where条件停止“PP”是非常明智的。这是避免将来不必要的错误的一件事。
UPDATE mytable
SET student_id = student_id + 'P'   --assumes already varchar 
WHERE RIGHT(student_id, 1) <> 'P'   --to stop having PP at end...
update @t
set studentid = studentid + 'P'