Avatar of 25112
25112
 asked on

add column schema as union to base table/view

consider a view vw_view1

how can you add a first line to the statement output

select * from vw_view1

so that the output is given as
col1,col2,col3,col4,col5.........................
data,data,data,data,data.................................
data,data,data,data,data.................................
data,data,data,data,data.................................
data,data,data,data,data.................................
Microsoft SQL ServerMicrosoft SQL Server 2005SQL

Avatar of undefined
Last Comment
25112

8/22/2022 - Mon
25112

ASKER
the reason is this is needed for a command line tool which does not output headers (bcp)
Eyal

select 'col1','col2','col3','col4'....
union all
select col1,col2,col3,col4.... from table
Kevin Cross

You may want to consider doing the output view SSIS package or Import/Export Wizard. You can do the UNION, but that requires the data type to match; therefore, you have to CAST/CONVERT all the columns in your data query to VARCHAR to match the column names row.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
25112

ASKER
thanks-
Eyal, that is not dynamic and also as mwvisa1 said, it is more complex than that.

mwvisa1,
>>output view
did you mean output window?

>>Import/Export Wizard
how?

>>you have to CAST/CONVERT
does it have to be done manually or possible to script it?
ASKER CERTIFIED SOLUTION
Kevin Cross

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
25112

ASKER
got you..