Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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,empLaborgroupFROM WCDATAtagcode empLaborgroup1132321P 200I would like the result to be "1132200", but when I trySELECT tagcode,empLaborgrouptagcode + empLaborgroupFROM 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