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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 insert from select

Author  Topic 

omsec
Starting Member

4 Posts

Posted - 2006-12-24 : 11:45:41
Yep, it's me again :-)

I have two Tabels, that look similar but not exactly the same. I wonder, what is the best way to copy a record from one Table to another. I tried something like this, which did not work:

insert into cmif_h
(Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate)
values
(select
Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate
from
cmif
where
Mandant = 5 and
AppID = 403220766
)


My Idea: I thought if I provide a result set that contains the same fields in the same order as specified in the INSERT INTO statement I could archive some "on-the-fly" copy operation.

Thanks in Advance - Roger

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-12-24 : 12:23:50
you can do this:

insert into cmif_h
select Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate
from cmif
where Mandant = 5 and AppID = 403220766


www.elsasoft.org
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2006-12-24 : 12:38:48
I guess my question is "Why do you need identical data in two different tables"? Kinda goes against the idea of a database, in general.

--Jeff Moden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-24 : 23:13:57
quote:
Originally posted by omsec

Yep, it's me again :-)

I have two Tabels, that look similar but not exactly the same. I wonder, what is the best way to copy a record from one Table to another. I tried something like this, which did not work:

insert into cmif_h
(Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate)
values
(select
Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate
from
cmif
where
Mandant = 5 and
AppID = 403220766
)


My Idea: I thought if I provide a result set that contains the same fields in the same order as specified in the INSERT INTO statement I could archive some "on-the-fly" copy operation.

Thanks in Advance - Roger


You shouldnt use Values when you do Insert into ..Select
insert into cmif_h
(Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate)
select
Mandant, AppID, CUser, CDate, MUser, MDate, IUser, IDate, FUser, FDate
from
cmif
where
Mandant = 5 and
AppID = 403220766



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-24 : 23:17:07
quote:
Originally posted by Jeff Moden

I guess my question is "Why do you need identical data in two different tables"? Kinda goes against the idea of a database, in general.

--Jeff Moden

I think it is just for practice to a newbie

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-12-25 : 02:23:06
quote:
Originally posted by Jeff Moden

I guess my question is "Why do you need identical data in two different tables"? Kinda goes against the idea of a database, in general.

--Jeff Moden



Aha just a guess may be for Audit Trailing purpose

Chirag

http://chirikworld.blogspot.com/
Go to Top of Page

omsec
Starting Member

4 Posts

Posted - 2006-12-25 : 05:13:03
Thank You.
Indeed, I am looking for a way to implement (DB-) Server-side auditing. And I want to avoid SQL-Code in my C#-Application, mostly due to performance and security thoughts.
Go to Top of Page

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-12-25 : 06:08:11
Aha.. Check out this links..there are some of the ways to impement it..

http://www.mindsdoor.net/SQLTriggers/AuditTrailTrigger.html
http://www.nigelrivett.net/SQLTriggers/Triggers_2_Creating_Audit_Trails.html


Chirag

http://chirikworld.blogspot.com/
Go to Top of Page
   

- Advertisement -