Solved

TSQL Combine (Concatenate) Several Rows Into  Single New Row

Posted on 2016-08-30
2
37 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 43

Accepted Solution

by:
zephyr_hex (Megan) earned 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

734 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