Sql

Hi,

I am talking to a Sql Server, from visual basic (6) and all i want to do is move all the fields associated with one record to another table on the sql server.
Both tables are in the same database on the sql server.
So i need an sql statement to execute this request. The table where i want to move the record has the same fields as the table from where the record is coming from.

Thanks!
mscalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LordSauceCommented:
I'm not quite sure if this is what you're after - this will copy the data from a selected record or records to a similar table (The syntax is Oracle, but should work in T-SQL - if not try removing brackets):

INSERT
INTO   table1
  (SELECT *
   FROM   table2
   WHERE  conditions);

If you then want to delete the old record(s) then use

DELETE
FROM   table2
WHERE  conditions;

Hope this helps.

0
mscalaAuthor Commented:
Yeah that was exactly what i needed, just the brackets had to be removed, thanks a lot for your help.
You can answer the question, so i can give the points to you.

Thanks again!
0
rovermCommented:
This will do the trick (the update statement):

UPDATE first
SET first.FIELDNAME = second.FIELDNAME
FROM TABLE1 first, TABLE2 second
WHERE condition

where:
TABLE1 = source table
TABLE2 = destination table
FIELDNAME = field to be updated

the phrases 'first' and 'second' are aliases.

grtx, RoverM
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

rovermCommented:
Sorry, forgot to say that:

CONDITION = the indicator to point the source table to the destionation table.
for example:
WHERE first.INDEXFIELD = second.INDEXFIELD

0
mscalaAuthor Commented:
Could : LordSauce answer my question, he came me the code that i needed

thanks!
0
twardCommented:
All you should have to do is click on the "Accept the Comment as the Answer" that should be over to the right of where it says "Comment"!!
0
LordSauceCommented:
mscala, glad to have been of service!

P.S. Next time, if a comment provides the answer, you can give the person the points by clicking on the 'Accept Comment as Answer' button.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.