Hi @Brendan Hager ,
Welcome to Microsoft Q&A!
Please also refer below example:
drop table if exists Table1
create table Table1
(project int,
Type varchar(10),
Date date,
Col1 varchar(10),
Col2 decimal(8,2))
insert into Table1 values
(1,'A','05-01-2021','ABC',12.51),
(2,'A','05-01-2021','ABC',12.51),
(3,'A','05-01-2021','ABC',12.51)
insert into Table1
select project,'B',DATEADD(DD,1,date),col1,Col2 from Table1
where type='A'
select * from Table1
Output:
project Type Date Col1 Col2
1 A 2021-05-01 ABC 12.51
2 A 2021-05-01 ABC 12.51
3 A 2021-05-01 ABC 12.51
1 B 2021-05-02 ABC 12.51
2 B 2021-05-02 ABC 12.51
3 B 2021-05-02 ABC 12.51
If you would like to list all columns, you could refer below:
SQL Server 2017 and later:
select string_agg(COLUMN_NAME,',') from information_schema.columns where table_name = 'Table1'
SQL Server 2016 and earlier:
select stuff(( select ','+ COLUMN_NAME from information_schema.columns where table_name = 'Table1'
FOR XML PATH('') ), 1, 1, '')
Output:
project,Type,Date,Col1,Col2
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.