Hi All,
Can somebody please help?..
here is the problem:-
if OBJECT_ID('tempdb..#test') is not null drop table #test
if OBJECT_ID('tempdb..#test1') is not null drop table #test1
if OBJECT_ID('tempdb..#test2') is not null drop table #test2
create table #test (
Typex varchar(255),
Column2 varchar(255),
Column3 varchar(255),
Column4 varchar(255),
Column5 varchar(255),
Column6 varchar(255),
Column7 varchar(255),
Column8 varchar(255),
Column9 varchar(255),
Column10 varchar(255)
)
create table #test1 (
Typex varchar(255),
Column2 varchar(255),
Column3 varchar(255),
Column4 varchar(255),
Column5 varchar(255),
Column6 varchar(255),
Column7 varchar(255),
Column8 varchar(255),
Column9 varchar(255),
Column10 varchar(255)
)
create table #test2 (
Typex varchar(255),
Column2 varchar(255),
Column3 varchar(255),
Column4 varchar(255),
Column5 varchar(255),
Column6 varchar(255),
Column7 varchar(255),
Column8 varchar(255),
Column9 varchar(255),
Column10 varchar(255)
)
insert into #test values('Type1','C1','C2','C3','C4','C5','C6','C7','C8','C9')
insert into #test1 values('Type2','C1','C2','C3','C4','C5',null,null,null,null)
insert into #test2 values('Type3','C1','C2','C3',Null,Null,NULL,NULL,NULL,NULL)
insert into #test values('Type1','C1',NULL,'C3',NULL,'C5','C6','C7','C8','C9')
insert into #test1 values('Type2','C1',NULL,'C3','C4','C5',null,null,null,null)
insert into #test2 values('Type3',NULL,'C2',NULL,Null,Null,NULL,NULL,NULL,NULL)
--10 columns
select * from #test
union all
--6 Columns
select * from #test1
union all
--4 Columns
select * from #test2
Result:-
When the above is saved as CSV, below is the result
when nulls have been removed it leaves commas for type 2 and type 3 beyond the expected columns
so for Type 1 should have 10 columns, Type 2 should have 6 columns and type 3 should have 4 columns
this is the Expected result:-
Is there a way to achieve the above?
Your help will be greatly apricated.
Many thanks