Concat question

  • I want to take the content of two columns, concatenate them and place them into the 3rd column.

    Something like:

    UPDATE    Table_name

    SET              Age_range = Age_start + '_' + Age_end

  • You should use an indexed calculated column since that way the data is maintained automatically and can't be overwritten:

    alter table Table_name drop column Age_range
    go
    alter table Table_name add Age_range as  Age_start + '_' + Age_end
    go
    create nonclustered index IX_NC_Table_name_Age_range on Table_name(Age_range)

    Better still, don't do this in the database at all as it's really a task for the presentation layer.

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

  • That does not work because it tries to create the column and a integer type.

  • alter table Table_name add Age_range as  cast(Age_start as varchar(10)) + '_' + cast(Age_end as varchar(10))

     

    Tim Wilkinson

    "If it doesn't work in practice, you're using the wrong theory"
    - Immanuel Kant

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

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