This should give you a good start.Hope it helps.
Create Table #test( PK Int, ID Int, Col1 Varchar(15), col2 Varchar(15), col3 DateTime)Create Table #Table1( PK Int, ID Int, Col1 Varchar(15), col2 Varchar(15), col3 DateTime)Insert Into #Table1 Values (1,11,'Test data','More Data',N'01/01/2010')Insert Into #Table1 Values (2,12,'Test data','More Data',N'01/02/2010')Insert Into #Table1 Values (3,13,'Test data','More Data',N'01/03/2010')Insert Into #Table1 Values (4,14,'Test data','More Data',N'01/04/2010')Insert Into #Table1 Values (5,15,'Test data','More Data',N'01/05/2010')Insert Into #Table1 Values (6,16,'Test data','More Data',N'01/06/2010')Insert Into #Table1 Values (7,17,'Test data','More Data',N'01/07/2010')Insert Into #Table1 Values (8,18,'Test data','More Data',N'01/08/2010')Insert Into #Table1 Values (9,19,'Test data','More Data',N'01/09/2010')Create Table #Table2( PK Int, ID Int, Col1 Varchar(15), col2 Varchar(15), col3 DateTime)Insert Into #Table2 Values (1,21,'Test data','More Data',N'01/01/2010')Insert Into #Table2 Values (2,22,'Test data','More Data',N'01/02/2010')Insert Into #Table2 Values (3,23,'Test data','More Data',N'01/03/2010')Insert Into #Table2 Values (4,24,'Test data','More Data',N'01/04/2010')Insert Into #Table2 Values (5,25,'Test data','More Data',N'01/05/2010')Insert Into #Table2 Values (6,26,'Test data','More Data',N'01/06/2010')Insert Into #Table2 Values (7,27,'Test data','More Data',N'01/07/2010')Insert Into #Table2 Values (8,28,'Test data','More Data',N'01/08/2010')Insert Into #Table2 Values (9,29,'Test data','More Data',N'01/09/2010')Declare @id intSet @id=0If @id=1 Begin Insert into #test (PK, ID, Col1, col2, col3) Select PK, ID, Col1, col2, col3 from #Table1 EndElse Begin Insert into #test (PK, ID, Col1, col2, col3) Select PK, ID, Col1, col2, col3 from #Table2 End Select * from #testDrop Table #testDrop Table #Table1Drop Table #Table2
Thank You,John