Showing posts with label datetime. Show all posts
Showing posts with label datetime. Show all posts

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

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

Friday, February 24, 2012

DTS/bcp a date into a datetime column

Is it possible to bcp a date like '1990-01-01' into a datetime column? The flat file does not contain any time.

I know it is possible using DTS and VB but I am trying to avoid this method. For those familiar with Oracle SQL Loader, you can specify a date format or date conversion function in a control file. I am wondering if I can use the function convert() in some similiar manner.

Thanks,
TPHBCP will handle all reccognized date formats. You do not need to do any type of conversions.