Inserting into table depending on conditions I'm trying to insert data into table but depending on the content it is supposed to be done different ways. My question is whether there exists such function that will work like follows:

WHEN Condition1 THEN INSERT INTO data1 SELECT * FROM table1

WHEN Condition2 THEN INSERT INTO data2 SELECT * FROM table2

...

ELSE SELECT 'done'
You should use IF...ELSE (Transact-SQL), ther is the complete example below:

declare @conditional_table table(col int);
insert @conditional_table values(1), (3), (4); 

declare @data1 table(col varchar(100));
declare @data2 table(col varchar(100));

declare @table1 table(col varchar(100));
insert @table1 values('table1');
declare @table2 table(col varchar(100));
insert @table2 values('table2');

declare @cnt int = 0;
--WHEN Condition1 THEN INSERT INTO data1 SELECT * FROM table1
-- let's say Condition1 is "there is 1 in @conditional_table"
if exists(select * from @conditional_table where col = 1)
begin
    insert into @data1 select * from @table1; 
    set @cnt = @cnt + 1;
end;

--WHEN Condition2 THEN INSERT INTO data2 SELECT * FROM table2
-- let's say Condition1 is "there is 2 in @conditional_table"
if exists(select * from @conditional_table where col = 2)
begin
    insert into @data2 select * from @table2;
    set @cnt = @cnt + 1;
end;

--ELSE SELECT 'done'
if @cnt = 0 
select 'done';

-------------------------
-- there was no 'done' selected because @count &gt; 1, some conditions were true
select * from @data1; -- condition1 was true, 'table1' will be returned
select * from @data2; -- condition2 was false, no data is returned