Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Copying column from other table .

Author  Topic 

davidmal
Starting Member

19 Posts

Posted - 2007-02-08 : 00:08:06
There are several easy ways to accomplish what I am trying to do in a simpler way however (long story short) this is something I need to learn for a much larger task in the near future.
O.K. I have a table named clients I'm trying to get started copying columns from the same table one by one. Lets say original table has these columns:
Database kokomain -- table dbo.clients
ID(pk) fname lname idate

I've created a blank temp table with the exact same schema and named it 'temp'. I've populated the id,fname and lname fields with the statement:
Insert Into kokomain.dbo.temp (cid,fname,lname) select c.cid,c.fname,c.lname from kokomain.dbo.clients c

Now, how could I add the idate field to the table as a separate query? I've tried several variations of things like...
INSERT INTO kokomain.dbo.temp (idate) select c.idate from kokomain.dbo.clients c where c.idate in (select idate from kokomain.dbo.temp)
No dice.

The correct statement would be greatly appreciated
Thanks.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-08 : 00:15:40
I don't seem to understand what you are trying to achieve?

1. Why don't you add date column in the same insert query as rest of the fields?
2.Why you are inserting idate from temp table to same temp table only?

Post some sample data and expected output.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

davidmal
Starting Member

19 Posts

Posted - 2007-02-08 : 00:30:23
What I tried to explain at the begining of the post is that this is not a problem I need a solution for. I need to learn how to copy individual columns of data that can be linked to unique keys in another table. In the example I gave it can key off the primary key.
Sample data:
dbo.clients dbo.temp
id fname lname idate id fname lname idate
1 Bill Smith 4/4/05 1 Bill Smith {null}
2 Sue Jones 5/4/06 2 Sue Jones {null}
3 Joe Davis 1/12/05 3 Joe Davis {null}
4 Steve Taylor 6/9/06 4 Steve Taylor {null}
How do you insert (IN A SEPATATE STATEMENT) the idate data from clients to temp. Please... I know very well I could just redo the query and include the idate but that's not what I need to learn how to do. Very long story short there is a method to my madness.
Thanks.

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-08 : 00:40:14

Update t
Set idate = c.idate
from kokomain.dbo.temp t
JOIN kokomain.dbo.clients c
on t.[id] = c.[id]


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

davidmal
Starting Member

19 Posts

Posted - 2007-02-08 : 00:47:48
harsh_athalye your awesome!!!

I tried a join similar but obviously had the syntax wrong somewhere.

Thanks again

Go to Top of Page
   

- Advertisement -