Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenate Question

Status
Not open for further replies.

szaunbr

Technical User
Jul 5, 2006
50
0
0
US
Hello, I am new to SQL Server and I have a question. I am trying to develop a VB 2005 application that has a combobox with all of the possible termination codes. I would like the combo box to display:

"code" - "description"
(the code, then a hyphen, then the description of the code)

I have one table that contains only two columns, the code, and then the description.

I am envisioning a view, that concat's the two, but I am getting an error message.

Example:

SELECT stu_leave_code +' - '+ code_desc
FROM student_leave_codes

error: The data types nchar and text are incompatible in the add operator.

Any help will be appreciated.
 
Maybe this would work...
Code:
select cast(stu_leave_code as varchar)+' - '+cast(code_desc as varchar)
from student_leave_codes
 
AHHHHH text field

Do this:


Code:
Select stu_leave_code + '-' + rtrim(convert(char(400), code_desc))

Where the 400 is should be a valid number that will be long enough to contain your largest description value

[small]"Mom........MEATLOAF!!!! DANG!!!![/small]
<.
 
okiiyama, without any specification of length, that defaults the values to a length of 30.




[small]"Mom........MEATLOAF!!!! DANG!!!![/small]
<.
 
Thank you monsnake, that worked out perfectly. I'm sure all of the suggestions would have worked fine, but I chose yours first and that worked.

Thank you so much.
 
No problem, glad to help.

[small]"Mom........MEATLOAF!!!! DANG!!!![/small]
<.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top