Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help a newbie!!

Author  Topic 

intat
Starting Member

1 Post

Posted - 2009-12-16 : 19:19:07
I'm trying to join 2 columns together to make 1.

Column 1 - PartCode
Column 2 - DateCode

Create a new Column 3 - HeatCode

PartCode DateCode HeatCode

12250 T169 T169-12250
10587 L139 L139-10587

Can someone help?
I'm using Access 2007 - Connected to a sql database.
Trying to set this up using a query..
Current Actual sql Code

SELECT TOP 100 PERCENT dbo.tblLab_Chemistry.PlantID, dbo.tblLab_Chemistry.LineID, dbo.tblLab_Chemistry.SampleCode, dbo.tblLab_Chemistry.PartCode,
dbo.vwPartCodeLookupTable.PartDescShort, dbo.tblLab_Chemistry.C, dbo.tblLab_Chemistry.Si, dbo.tblLab_Chemistry.Mn, dbo.tblLab_Chemistry.P,
dbo.tblLab_Chemistry.S, dbo.tblLab_Chemistry.Mg, dbo.tblLab_Chemistry.Cr, dbo.tblLab_Chemistry.Cu, dbo.tblLab_Chemistry.Sn,
dbo.tblLab_Chemistry.Ce, dbo.tblLab_Chemistry.Al, dbo.tblLab_Chemistry.Ti, dbo.tblLab_Chemistry.ProductionDate,
dbo.vwPartCodeLookupTable.iron_chemistry, dbo.tblLab_Chemistry.UniqueID, dbo.GetDateCode2(dbo.tblLab_Chemistry.ProductionDate,
dbo.tblLab_Chemistry.PlantID) AS DateCode
FROM dbo.tblLab_Chemistry LEFT OUTER JOIN
dbo.vwPartCodeLookupTable ON dbo.tblLab_Chemistry.PartCode = dbo.vwPartCodeLookupTable.part_code
WHERE (dbo.tblLab_Chemistry.PlantID = 1 OR
dbo.tblLab_Chemistry.PlantID = 2) AND (dbo.tblLab_Chemistry.LineID = 2 OR
dbo.tblLab_Chemistry.LineID = 3)
ORDER BY dbo.tblLab_Chemistry.UniqueID DESC

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-16 : 19:22:32
Just concatenate them together using +:

SELECT Column1 + Column2 AS Column3
FROM Table1

or if you want to add a dash:

SELECT Column1 + '-' + Column2 AS Column3
FROM Table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-12-17 : 01:58:26
If any one of the columns is of INT type you need to convert it into a varchar

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -