Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server-2008
Ho to concatenate two columns in SQL Server 2008.
 
Example Below
-------------
ID(int)     Year(int)     
-------     ---------
10           2008
20           2009
30           2010
Output should come as below
ID_Year (Output)
-------
10-2008
20-2009
30-2010
How to query in SQL Server 2008.
Posted 3-Jan-12 20:37pm
gani77871.3K
Edited 3-Jan-12 20:42pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the following :
 
select Convert(nvarchar(50),ID)+'-'+Convert(nvarchar(50),Year) as ID_Year from tablename
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try also
SELECT (ID + '-' + year) AS ID_Year
FROM tablename
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

select distinct cast(ID+ '-' + Year as varchar(100)) as newcolumn from tablename
  Permalink  
v2
Comments
anghan22 at 27-Apr-13 0:16am
   
i want to string and int concat plz give me..
soluction
 

e.g
 
KK-2
AA-3
 

above look like...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

u can use Sql Query like:-
 
select cast(id as varchar)+'-'+ cast(year as varchar) as ID_year
 
Hope, this will help you...
  Permalink  
v2
Comments
CHill60 at 10-Dec-13 7:33am
   
It is better for you to vote for the solution than posting a comment as a solution in its own right. You will only attract downvotes and reports
Jain Nishant at 11-Dec-13 0:03am
   
Now, u can vote for me....

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

  Print Answers RSS
0 OriginalGriff 527
1 CPallini 510
2 Sergey Alexandrovich Kryukov 438
3 George Jonsson 271
4 Afzaal Ahmad Zeeshan 184
0 OriginalGriff 5,370
1 CPallini 4,360
2 Sergey Alexandrovich Kryukov 3,822
3 George Jonsson 3,037
4 Gihan Liyanage 2,435


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 11 Dec 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100