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.
| Author |
Topic |
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2009-12-07 : 11:18:42
|
| How can I concatenate several fields to one string?I want to create a string from 2 VARCHAR fields and a DateTime fieldThis is my attempt below, but it errored saying Msg 245, Level 16, State 1, Line 1Conversion failed when converting the varchar value 'ASV' to data type int.JobType+''+ApptJobNo+''+CONVERT(VARCHAR(10), ApptDate,101) AS Taghow can I get this to work? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-12-07 : 11:21:19
|
is JobType & AppJobNo both string ? if not convert to string first before concat KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-12-07 : 11:21:52
|
If one of the fields is numeric datatype then use convert to varchar.example:convert(varchar(255),JobType)+''+convert(varchar(255),ApptJobNo)+''+CONVERT(VARCHAR(10), ApptDate,101) AS TagBecause concatenating is not possible with numeric data type without convert. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2009-12-07 : 11:24:51
|
| Excellent, thanks for that :-) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-12-08 : 01:47:15
|
Also you dont need dummy single quotes but I guess it should be a single spaceconvert(varchar(255),JobType)+' '+convert(varchar(255),ApptJobNo)+' '+CONVERT(VARCHAR(10), ApptDate,101) AS Tag MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|