Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ItmsGrpCod(smallint)	ItmsGrpNam(nvarchar)
100	                 Items
101	                   Accessories
102	                 HP Printers
103	               IBM Printers
104	               PCs
105	               Servers 


i need out put this..
100-Items
101-ACCESSORIES @ 5
102-AIRTEL DTH
103-AKSHAYA GRINDER
104-AMBAL GRINDER
105-ASAL INDCOOK
106-BAJAJ APPLIANCES
Posted
Updated 17-Apr-13 2:36am
v2

select cast(itmsgrpCod AS VarChar) + '-' + itmsgrpNam

from tbl


I can't help but comment on the appaling column names on your tables though

What's wrong with ItemsGroupCode?
 
Share this answer
 
Comments
Maciej Los 17-Apr-13 8:43am    
Good answer, +5!
Please, see my answer. I had added some extra informations.
Write sql query as below

SQL
select ItmsGrpCod +'-'+ ItmsGrpNam from TableName.
 
Share this answer
 
Comments
DhananjayanP 17-Apr-13 8:27am    
it's having error Conversion failed when converting the nvarchar value 'Accessories' to data type smallint.
For MS SQL Server 2012 use CONCAT[^] function, for previous use "+": + (String Concatenation) (Transact-SQL)[^]

Some time, you need to use CAST and CONVERT[^] functions:
SQL
SELECT CONVERT(VARCHAR(30), ItmsGrpCod) + '-' + ItmsGrpNam AS [NewCode]
 
Share this answer
 
v2

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