Copying from one column to another with truncation.

  • Hi Guys

    I have a table called Mytable.

    In it are 2 columns, Description(50 Char) and Longdescription(200 char)

    I need to copy the content of longdescritption(data with more tha 50 characters) into my descritption table.

    I dont mind if it copys the first 50 characters of the data and truncates the rest.

    How do I acheive this ?

    Thanks in advance.

    A

  • Hi,

    if the column Description(50 Char) doesn't have any value (or values can be overwritten) and you need to copy values to it from Longdescription(200 char) column, you can use the next query:

    update Mytable set Description=substring (Longdescription, 1, 50)

    if the column Description(50 Char) has some values that you don't want to be overwritten, you can add values from Longdescription(200 char) to the end of the Description(50 Char) column:

    insert into Mytable (Description)

    select substring(Longdescription, 1, 50) from Mytable

  • Hi SSCveteran

    Thanks you for the assistance, worked great.

    Im pretty new to this and appreciate the assistance.

    A

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

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