Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 41
  • Last Modified:

TSQL Combine (Concatenate) Several Rows Into Single New Row

Hello,

I'm trying to create a Unique ID from several fields in my table by combining several rows into a single row.

Here's a select statement that (I think) is outputting what I want:

SELECT (CAST(BIRTH_DATE as VARCHAR(10))+(CAST(BEGIN_DATE as VARCHAR(10)))+RACE+SEX) 
FROM MyTable_t

Open in new window


I would like to take the output of the above select and insert it into the MyID field in MyTable_t.

Any help will be greatly appreciated - thanks!
0
ttist25
Asked:
ttist25
1 Solution
 
zephyr_hex (Megan)DeveloperCommented:
MS SQL will allow you to update the same table you select from, like so:

UPDATE t SET t.MyID = (CAST(t.BIRTH_DATE as VARCHAR(10))+(CAST(t.BEGIN_DATE as VARCHAR(10)))+t.RACE+t.SEX) 
FROM MyTable_t

Open in new window

1
 
ttist25Author Commented:
Thanks for this.  Worked great!
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now