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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Combine Two Columns

Author  Topic 

Gary Costigan
Yak Posting Veteran

95 Posts

Posted - 2005-04-27 : 18:21:52
I'm trying to combine the first four numbers of the "tagcode" column with all the data in the "emplaborgroup" column but I keep getting an error.

Here is an example of the raw data.

SELECT tagcode,
empLaborgroup
FROM WCDATA

tagcode empLaborgroup
1132321P 200

I would like the result to be "1132200", but when I try

SELECT tagcode,
empLaborgroup
tagcode + empLaborgroup
FROM WCDATA

to combine the two columns I get the error "Syntax error converting the varchar value '1132321P' to a column of data type smallint".

I've played around with CONVERT but I'm not having any luck in figuring out how to pull just the first four numbers from the tagcode.

Any help would be appreciated.

Thx.

GC

mpetanovitch
Yak Posting Veteran

52 Posts

Posted - 2005-04-27 : 20:19:10
Here you go.


SELECT tagcode,
empLaborgroup,
SUBSTRING(tagcode, 1, 4) + CAST(empLaborgroup AS varchar)
FROM WCDATA


Mike Petanovitch
Go to Top of Page
   

- Advertisement -