0

I need to merge some column value into one column with varchar/nvarchar data type.

I tried to use Computed Column Specification in Table Designer, but I only know how to compute int data type.

| Column1 |  | Column2 |  | Column3 |  |MergedColumn|
|    A    |  |    B    |  |    C    |  |    AB-C    |
|    A1   |  |    B1   |  |    C1   |  |  A1B1-C1   |

I need that result in MergedColumn.

5
  • You can try using concat the columns you want and update the last column. learn.microsoft.com/en-us/sql/t-sql/functions/… Commented Aug 16, 2019 at 2:15
  • I use concat as select, but I need the result like a normal column. Commented Aug 16, 2019 at 2:25
  • I think you want to look up views and computed columns. Commented Aug 16, 2019 at 2:28
  • So @shawnt00 you mean that is possible only in views? Commented Aug 16, 2019 at 3:07
  • No, I think you could probably choose one or the other to do what you need. It sounds like you might have tried a computed column though it's unclear what you meant by the "int" thing. Commented Aug 16, 2019 at 4:45

1 Answer 1

2

The CONCAT function should work here:

SELECT
    Column1,
    Column2,
    Column3,
    CONCAT(Column1, Column2, '-', Column3) AS MergedColumn
FROM yourTable;
Sign up to request clarification or add additional context in comments.

2 Comments

How to place this syntax as column?
ALTER TABLE yourTable ADD MergedColumn AS CONCAT(Column1, Column2, '-', Column3) PERSISTED that should do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.