Update with comma embeded

  • Hi,

    I am trying to run this update SQL statement and got an error

    UPDATE Task SET TaskName = 'Reading', Comment = 'Books, Magazines, Brochures' Where TaskID = 5

    The problem is there are commas in the text value of the Comment column. How can I get around this? Thanks!

    I am really appreciate your help.

    Thach

  • I don't seem to get an error when I run this code on my SQL Server 2000 machine:

    create table task(taskid int, taskname varchar(100), comment varchar(100))

    insert into task values (5, 'garbage','garbage, garbage')

    UPDATE Task SET TaskName = 'Reading',

    Comment = 'Books, Magazines, Brochures'

    where taskid = 5

    select * from task

    drop table task

    If you really don't like the commas, you could also code it like this:

    create table task(taskid int, taskname varchar(100), comment varchar(100))

    insert into task values (5, 'garbage','garbage, garbage')

    UPDATE Task SET TaskName = 'Reading',

    Comment = 'Books' + char(44) + ' Magazines' + char(44) + ' Brochures'

    where taskid = 5

    select * from task

    drop table task

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • Coma does not make any difference here. What error message are you getting?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply