SQL Insert Into New Table Or Else Insert Overwrite Into Existing Table
Since you are not going to specify the column names you are going to have to go with SELECT * it is not ideal, but works if the tables are going to be new.

You could do it with the query below, but you will have to change your grouping columns each time. Unless you can simply use DISTINCT.

If your tables are big, You should look into splitting it in batches.

More info on batches

Test TableA

CREATE TABLE  dbo.tbl_A(ID INT, Val varchar(255));

INSERT INTO  dbo.tbl_A(id,val) 
VALUES(1,'bla'),(1,'bla'),(2,'bla'),(2,'ugh'),(3,'bla');


Query with group by

IF (EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'dbo' 
                 AND  TABLE_NAME = 'tbl_B'))
BEGIN
    TRUNCATE TABLE dbo.tbl_B
    INSERT INTO  dbo.tbl_B
    SELECT * 
    FROM dbo.tbl_A
    GROUP BY ID,VAL;
END
ELSE 
BEGIN
    SELECT * 
    INTO dbo.tbl_B
    FROM dbo.tbl_A
    GROUP BY ID,VAL;
END


Query with distinct

  IF (EXISTS (SELECT * 
                     FROM INFORMATION_SCHEMA.TABLES 
                     WHERE TABLE_SCHEMA = 'dbo' 
                     AND  TABLE_NAME = 'tbl_B'))
    BEGIN
        TRUNCATE TABLE dbo.tbl_B
        INSERT INTO  dbo.tbl_B
        SELECT DISTINCT * 
        FROM dbo.tbl_A;
    END
    ELSE 
    BEGIN
        SELECT DISTINCT * 
        INTO dbo.tbl_B
        FROM dbo.tbl_A;
    END


DB&lt;>Fiddle