Click here to Skip to main content
14,643,428 members
Rate this:
Please Sign up or sign in to vote.
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

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
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,

try this

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.
   
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'
Rate this:
Please Sign up or sign in to vote.

Solution 1

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:

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
   
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.

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




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