Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with concatenation - Concatenate the data from two columns to the data in main column

Status
Not open for further replies.

Almie

Technical User
Nov 28, 2006
39
US
I am using SQL2012, Using SSMS, I am trying to concatenate data from two columns into a columns that already has data. The Class_id and Qual_id are in the Statute table, BUT, I need to write a select statement to pull the Class _Code referencing the Class_id from the Class table and the same with the Qual_code and the Qual_id from the Qual table.
Sample of Statute table:
Statute Class_id Qual_id
28-701A 1000001 1000003

I need the data to appear in the Statute columns like this:
Statute
28-701a (M1) (DV)

I want to pull in the Class Code for the specific Class_id from the Class table
Class_Id Class_code
1000001 M1
I want to pull in Qual Code for the specific Qual_ID from the Qual table
Qual_Id Qual_code
1000003 DV
 
Update Statute
SET Statute = Statute + ' ('+class_code+') ('+qual_code+')'
FROM
Statute
JOIN Class on class.class_id = statute.class_id
JOIN Qual on qual.qual_id = statute.qual_ID

Check out Pinal Dave's explanation, and do some reading on the UPDATE...FROM structure.

-----------
With business clients like mine, you'd be better off herding cats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top