How to insert new values in single column in sql databse

Viewed 89

I need to insert values into the database. In my case while user enter any message click update button that message need to update on Chats column in comma(,) separated values.

I tried in this method:

This is demo of my Database Looks like

I need output like this:

This want output look like this.

How to write SQL query for this method?

1 Answers

Try this:

  DECLARE @ID INT;
  UPDATE [User] SET Chats=(STUFF( (SELECT ','+us.Chats  FROM  [User] us WHERE us.id=@ID FOR XML PATH('')),1,1,'')) +','+N'NEW CHATS'
  WHERE id=@ID
Related