adding and appending

  • I have a column with these values 100/200,200/300,300/400 .

    I need to add the values and the result will be

    A300,A500,A700 with A appended after adding the values. How do I achieve this

    Thanks

  • Hi

    as long as data length is as provided:

    'A' + CAST(CAST(LEFT("yourdata", 3) AS int) + CAST(SUBSTRING("yourdata", 5, 3) AS int) AS char)

    regards Graham

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • It gives me this error :

    Server: Msg 256, Level 16, State 1, Line 5

    The data type int is invalid for the substring function. Allowed types are: char/varchar, nchar/nvarchar, and binary/varbinary.

  • try this

    'LC' + CAST(CAST(RIGHT (RTRIM(ID), 3) AS INT) + CAST(LEFT (LTRIM(ID), 3) AS INT) AS char)

    please follow the advice in the link below ... you will get faster and more detailed and accurate replies

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

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

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