I have data in several fields that need comma separated and combined in one field. I will called the output field MyResults
MyReults will begin with F1 for field01, F2 for field02, and so on.
The data in MyResults should not begin or end with a comma.
Below is code to create the table and sample data. I am looking for assistance to write a query that will produce the data in the MyResults field
View Data.
select * from aaTemp
[!]Attention![/!]
EXPECTED RESULTS
Output 1: F1-A,F3-Z,F6-X
Output 2: F1-A,F2-B,F5-K,F6-Y
Output 3: F2-B,F3-A,F4-D,F5-K,F6-Y
Output 4: F1-J,F2-I,F3-C,F4-E,F5-F
Output 5: F2-I,F3-A,F4-E,F5-F
Output 6:
Output 7: F2-B
Jim
MyReults will begin with F1 for field01, F2 for field02, and so on.
The data in MyResults should not begin or end with a comma.
Below is code to create the table and sample data. I am looking for assistance to write a query that will produce the data in the MyResults field
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[aaTemp](
[Field01] [nvarchar](50) NULL,
[Field02] [nvarchar](50) NULL,
[Field03] [nvarchar](50) NULL,
[Field04] [nvarchar](50) NULL,
[Field05] [nvarchar](50) NULL,
[Field06] [nvarchar](50) NULL
) ON [PRIMARY]
GO
INSERT into aaTemp Values ('A','','Z','','','X')
INSERT into aaTemp Values ('A','B','','','K','Y')
INSERT into aaTemp Values ('','B','A','D','K','Y')
INSERT into aaTemp Values ('J','I','C','E','F','')
INSERT into aaTemp Values (' ','I','A','E','F','')
View Data.
select * from aaTemp
[!]Attention![/!]
EXPECTED RESULTS
Output 1: F1-A,F3-Z,F6-X
Output 2: F1-A,F2-B,F5-K,F6-Y
Output 3: F2-B,F3-A,F4-D,F5-K,F6-Y
Output 4: F1-J,F2-I,F3-C,F4-E,F5-F
Output 5: F2-I,F3-A,F4-E,F5-F
Output 6:
Output 7: F2-B
Jim