Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TSQL Combine (Concatenate) Several Rows Into  Single New Row

Posted on 2016-08-30
2
Medium Priority
?
40 Views
Last Modified: 2016-08-30
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
Comment
Question by:ttist25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 44

Accepted Solution

by:
zephyr_hex (Megan) earned 2000 total points
ID: 41776715
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
 
LVL 1

Author Closing Comment

by:ttist25
ID: 41776765
Thanks for this.  Worked great!
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question