Click here to Skip to main content
15,890,336 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can i combine more then two columns data into one temporary column

actually i joined two tables that looks like this
-------------------------------------------------------------------------
First_Name  Email_Id              City        State        industry_type  
nitish      pvss341@gmail.com    vijayawada    AP            IT
TEJA        TEJA341@gmail.com    vijayawada    AP            IT
MANI        MANI341@gmail.com    vijayawada    AP            IT



//BY USING BELOW QUERY I GOT THIS TABLE

SQL
select r.First_Name,r.Email_Id,r.City,r.State,e.industry_type
from Registration as r
inner join Experience_Detail as e
on r.Login_Id=e.Login_Id


NOW I WANT THE RESULT SHOULD BE LIKE THIS BELOW TABLE
-----------------------------------------------------------------------------

First_Name  Email_Id              City        State industry_type  FullDetails  
nitish      pvss341@gmail.com    vijayawada    AP     IT       [by-nitish,email_id,
TEJA        TEJA341@gmail.com    vijayawada    AP     IT        vijayawada,AP,IT]  
MANI        MANI341@gmail.com    vijayawada    AP     IT


[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 18-Jan-13 21:02pm
v3
Comments
Arun kumar Gauttam 19-Jan-13 2:29am    
plz explain your problem briefly

Assuming that they are (for example) strings, try:
SELECT myColumn1 + myColumn2 AS DisplayName FROM myTable


"I Modified the question sir."

The answer is still the same - you just have to expand it a bit:

SQL
select r.First_Name,r.Email_Id,r.City,r.State,e.industry_type,
       '[by-' + r.First_Name + ',' + r.Email_Id + ',' + r.City +
              ',' + r.State + ',' + e.industry_type AS FullDetails
from Registration as r
inner join Experience_Detail as e
on r.Login_Id=e.Login_Id
 
Share this answer
 
v2
Comments
ntitish 19-Jan-13 2:46am    
I Modified the question sir.
ntitish 19-Jan-13 3:38am    
i want to display fulldetails in a gridview like below.
by-nitish,
pvss341@gmail.com,
city-vijayawada,
state-AP.

//but i am getting now like this
By-Yash,connect2yash@gmail.com,vijayawada,Delhi.
Hi,

try this

SQL
select r.First_Name,r.Email_Id,r.City,r.State,e.industry_type,
r.First_Name+','+r.Email_Id+','+r.City+','+r.State+','+e.industry_type AS FULLDETAILS
from Registration as r
inner join Experience_Detail as e
on r.Login_Id=e.Login_Id


NOTE: By using Concatinate the columns you fetch this result, if the datatype of all columns is different then you must use convertion.
 
Share this answer
 
Comments
ntitish 22-Jan-13 7:30am    
sir i am getting one more error sir,when there is a null value in e.industry_type then r.First_Name+','+r.Email_Id+','+r.City+','+r.State+','+e.industry_type=null value it is getting here i want i want to replace null value with space.can i do in this query.
ntitish 22-Jan-13 7:31am    
//this was my code but it is showing error

select r.login_id,r.First_Name,r.Email_Id, isnull(e.industry_type,' ') as e.industry_type,'Name-'+r.First_Name+'<br>'+r.Email_Id +'<br>'+'IndustryType-'+e.industry_type as fulldetails
from Registration as r
inner join Experience_Detail as e
on r.Login_Id=e.Login_Id and status='Active' and Designation='User'

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