Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ItemCode(nvarchar)
A00001
A00002
A00003
A00004
A00005


ItemName(nVarchar)
IBM Infoprint 1312
IBM Infoprint 1222
IBM Infoprint 1226
IBM Infoprint 1226
HP Color Laser Jet 5

Output I need like this
A00001-IBM Infoprint 1312
A00002-IBM Infoprint 1222
A00003-IBM Infoprint 1226
A00004-IBM Infoprint 1226
A00005-HP Color Laser Jet 5
Posted
Updated 15-Apr-13 6:46am
v3

You can use the CONCAT[^] function to concatenate output from columns.
 
Share this answer
 
Comments
Maciej Los 15-Apr-13 2:58am    
This is very good answer for MS SQL server 2012. See my answer.
See solution 1. It's very good for MS SQL Server 2012. but for earlier version you need to use "+": + (String Concatenation) (Transact-SQL)[^]

Test it:
SQL
SELECT CONVERT(NVARCHAR(80), ItemCode + '-' + ItemName) AS NewName
FROM YourTable
 
Share this answer
 
v2
Comments
Abhinav S 15-Apr-13 4:18am    
Good point. A 5.
Maciej Los 15-Apr-13 4:26am    
Thank you, Abhinav ;)
use plus sign...
SQL
select ItemCode + '-' + ItemName As col1 from table_name

Happy Coding!
:)
 
Share this answer
 
Comments
Abhinav S 15-Apr-13 4:18am    
Of course. 5.
Aarti Meswania 15-Apr-13 4:19am    
Thank you! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900