views:

43

answers:

4

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?

+1  A: 

This is for SQL Server:

select cast(Studentid as varchar) +'P' from student
TskTsk
+2  A: 
UPDATE mytable SET student_id=CONCAT(student_id,'P');//mysql
dnagirl
accepted and for MySQL? And comment to Q states SQL Server 2005? Lucky you ;-)
gbn
+3  A: 
UPDATE mytable
SET student_id = student_id + 'P'   --assumes already varchar 
WHERE RIGHT(student_id, 1) <> 'P'   --to stop having PP at end...
gbn
+1  A: 
update @t
set studentid = studentid + 'P'
priyanka.sarkar