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
 SQL Server Development (2000)
 Combine varchar & int into one column

Author  Topic 

bntringa
Starting Member

5 Posts

Posted - 2006-05-18 : 12:59:23
Hey all,

I am trying to combine a varchar column and an int column into one new column via the following sample:

SELECT VC1 + ' ' + INT1
FROM Test

VC1 is varchar (10)
INT1 is int (4)

This works fine with two varchar columns, but introducing the int field causes the following error:

"Syntax error converting the varchar value to a column of data type int".

Is there a way to specify the new column type are varchar to handle this correctly?

thanks!

- Brian

mmahmed
Starting Member

6 Posts

Posted - 2006-05-18 : 13:21:29
Hi Brian

Try the following:
SELECT VC1 + ' ' + CAST(INT1 as varchar(10))
FROM Test

Cheers
Moosh
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-05-18 : 13:21:38
SELECT VC1 + ' ' + CONVERT(varchar(20), INT1)
FROM Test

Kristen
Go to Top of Page
   

- Advertisement -