UPDATE Record's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JSuresh
    New Member
    • Jun 2007
    • 8

    UPDATE Record's

    Hi Dude's,

    i want to update the cutomer table in customer id UA001 to UA0001, UA100 to UA0100 like that all records, i have plenty of records in this table please help me. I am using Sql Server 2005.


    Thanks & Regards,
    J Suresh
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Find it here

    Just use the WHERE clause.

    -- CK

    Comment

    • Delerna
      Recognized Expert Top Contributor
      • Jan 2008
      • 1134

      #3
      If I understand your question correctly, then

      [code=sql]
      UPDATE CustomerTable SET CustID=left(Cus tID,2) + '0' + right(CustID,le n(CustID)-2)
      [/code]

      you might want to test that with a select before running the update first.
      [code=sql]
      SELECT CustID,left(Cus tID,2) + '0' + right(CustID,le n(CustID)-2) as NewCustID
      FROM CustomerTable
      [/code]
      if the NewCustID looks OK, then you can run the update.

      Comment

      • JSuresh
        New Member
        • Jun 2007
        • 8

        #4
        Hi,

        Thanks for your reply, When i use the SELECT query its working fine,

        Party_id(char-15) Customer_id(var char-15)
        SA00001 SA000001 *******
        SA00002 ******* SA000002 *******
        SA00003 ******* SA000003 *******
        SA00004 ******* SA000004 *******
        SA00005 ******* SA000005 *******

        While try to UPDATE its showing error becoz its a varchar(15) datatype.

        I place the error below.

        Error :
        Msg 8152, Level 16, State 14, Line 1
        String or binary data would be truncated.
        The statement has been terminated.

        Please help me in this

        Originally posted by Delerna
        If I understand your question correctly, then

        [code=sql]
        UPDATE CustomerTable SET CustID=left(Cus tID,2) + '0' + right(CustID,le n(CustID)-2)
        [/code]

        you might want to test that with a select before running the update first.
        [code=sql]
        SELECT CustID,left(Cus tID,2) + '0' + right(CustID,le n(CustID)-2) as NewCustID
        FROM CustomerTable
        [/code]
        if the NewCustID looks OK, then you can run the update.

        Comment

        • Delerna
          Recognized Expert Top Contributor
          • Jan 2008
          • 1134

          #5
          Are you sure its a varchar(15) and not char(15)

          If it's char(15) then try this
          [code=sql]
          UPDATE CustomerTable SET CustID=left(rtr im(CustID),2) + '0' + right(CustID,le n(rtrim(CustID) )-2)
          [/code]
          char(15) will have 15 characters..... always. So the original update query would make it 16 characters and therefore generate the error.

          If it is varchar(15) then one or more fields has 15 characters in them and adding the extra character makes 16 and therefore the error.
          In this case you will need to chage the field in the table so it is varchar(16)

          Comment

          • JSuresh
            New Member
            • Jun 2007
            • 8

            #6
            Thank you ,

            Its working excelent.

            Thanks & Regards,
            JSuresh

            Originally posted by Delerna
            Are you sure its a varchar(15) and not char(15)

            If it's char(15) then try this
            [code=sql]
            UPDATE CustomerTable SET CustID=left(rtr im(CustID),2) + '0' + right(CustID,le n(rtrim(CustID) )-2)
            [/code]
            char(15) will have 15 characters..... always. So the original update query would make it 16 characters and therefore generate the error.

            If it is varchar(15) then one or more fields has 15 characters in them and adding the extra character makes 16 and therefore the error.
            In this case you will need to chage the field in the table so it is varchar(16)

            Comment

            Working...