January 30, 2011 at 9:13 pm
Dear All,
I have table where i need to do the column and row concatenation for some of the fields.
Table structure:
Id address1 address2 address3
1 A B C
2 X Y Z
My output should be in the form of
ID changes
1 address1=A address2=B address3=C
2 address1=X address2=Y address3=Z
How to do this pls help me.
Thanks,
Gangadhara MS
SQL Developer and DBA
January 30, 2011 at 9:50 pm
Gangadhara MS (1/30/2011)
Dear All,I have table where i need to do the column and row concatenation for some of the fields.
Table structure:
Id address1 address2 address3
1 A B C
2 X Y Z
My output should be in the form of
ID changes
1 address1=A address2=B address3=C
2 address1=X address2=Y address3=Z
How to do this pls help me.
Thanks,
Gangadhara MS
SQL Developer and DBA
Hi Gangadhara, I cannot believe that you would want to ask a question like this and you are a DBA. Well, maybe you have your reasons and here is my code. I hope I am not missing something here and hit my name with a plank.
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[concatme]') AND type in (N'U'))
begin
create table concatme(id int not null primary key, address1 nvarchar(5) null, address2 nvarchar(5) null, address3 nvarchar(5) null)
insert concatme
select 1 id, 'A' a1, 'B' a2, 'C' a3
union select 2 id, 'X' a1, 'Y' a2, 'Z' a3
end
select id, 'Address1 = '+address1+' Address2 = '+address2+' Address3 = '+address3 change from concatme
:-PManie Verster
Developer
Johannesburg
South Africa
I can do all things through Christ who strengthens me. - Holy Bible
I am a man of fixed and unbending principles, the first of which is to be flexible at all times. - Everett Mckinley Dirkson (Well, I am trying. - Manie Verster)
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply