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 |
|
Apples
Posting Yak Master
146 Posts |
Posted - 2008-02-29 : 11:49:22
|
| I have a table like this:tbl_Projects-------------------------ProjID | Description------------------------- 1 | First 2 | Second 3 | ThirdI want to write a SELECT statement that will output in this format: 1 - First 2 - Second etc...I've tried these two statements:SELECT (ProjID + ' - ' + Description) AS ProjectsFROM tbl_Projects//Error: Conversion failed when converting the varchar value 'First' to data type int.andSELECT CONCAT(ProjID, CONCAT(' - ', Description)) AS ProjectsFROM tbl_Projects//Error: The data types int and varchar are incompatible in the concat operator.Is there any way to concatenate an int value with a varchar value? |
|
|
jdaman
Constraint Violating Yak Guru
354 Posts |
Posted - 2008-02-29 : 11:58:51
|
| [code]DECLARE @sample TABLE ( id INT, val VARCHAR(6) )INSERT @sample ( id, val )SELECT 1, 'First' UNIONSELECT 2, 'Second' UNIONSELECT 3, 'Third'SELECT CAST(id AS VARCHAR)+' - '+val FROM @sample[/code] |
 |
|
|
slimt_slimt
Aged Yak Warrior
746 Posts |
Posted - 2008-03-01 : 16:10:50
|
you are having problems merging int and varchar field; i assume.use CAST to convert int to varchar.select projid ,description ,cast(projId as varchar)+ ' - ' +description as full_namefrom tbl_project |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|