Wednesday, March 21, 2012

Dumping rows of 2 columns of a table to a different table with different no of columns

Hi,

I have two tables

Table Source

{

category varchar(20),

LastUpdate datetime

}

Table Destination

{

SubjectId varchar(20),

SubjectDate datetime,

category varchar(20),

LastUpdate datetime

}

Please note that the number columns are different in each table.

I wanted to dump the data of Source table to Destination table. I meant to say that the rows of 2 columns in Source table to last 2 rows of Destination table.

And also my oreder of the columns in Destination table will vary. So i need to a way to dynamically insert the data in bulk. but i will know the column names for sure before inserting.

Is there anyway to bulk insert into these columns.

Your quick response will be appreciated

~Mohan Babu

It is a very simple solution:

1. create a view on destination
CREATE VIEW [viewDestination]
AS
SELECT category, LastUpdate
FROM dbo.Destination

2. Then
insert into dbo.viewDestination
select * from Source

doesn't matter the order in Destination table.|||Thanks for the reply.But i don't want to create a view on this as the number of coulmns on the table will be changed dynamically. Can you please suggest any other way

No comments:

Post a Comment