Click here to Skip to main content
11,414,619 members (65,926 online)
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 21:37pm
gani77871.3K
Edited 3-Jan-12 21:42pm
Mehdi Gholam270.4K
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  
Comments
Member 11071777 at 8-Nov-14 22:07pm
   
How to concatenate multiple tables into a single table(every table has the same column name)in SQL server 2008
Bebosh at 18-Jan-15 4:57am
   
Yes, this is what I want .. Million thanks
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 5

SELECT Title,
FirstName,
lastName,
ISNULL(Title,'') + ' ' + ISNULL(FirstName,'') + ' ' + ISNULL(LastName,'') as FullName
FROM Customer
  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 Sergey Alexandrovich Kryukov 9,160
1 OriginalGriff 7,487
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web03 | 2.8.150427.4 | Last Updated 20 Dec 2014
Copyright © CodeProject, 1999-2015
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