- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-10-28 01:57 AM . Last Modified: 2023-05-03 12:08 AM
SQL Insert into table
Hi,
can I use
INSERT INTO table2
SELECT * FROM table1
WHERE condition;
Or is there some other method?
Thanks,
- Labels:
-
SCADA
Link copied. Please paste this link to share this article on your social media post.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-10-28 06:23 AM
you absolutely can but you need to ensure that the columns match up or explicitly define them in the select statement. I've also noticed that the application doesn't like it if you use parenthases to wrap the select statement.
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-10-28 06:23 AM
you absolutely can but you need to ensure that the columns match up or explicitly define them in the select statement. I've also noticed that the application doesn't like it if you use parenthases to wrap the select statement.
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-10-28 12:28 PM . Last Modified: 2020-10-29 02:07 AM
So something like below should work in a mimic script
Set Table1 = Server.FindObject("XXX.XXX1")
Set Table2 = Server.FindObject("XXX.XXX2")
SelectedRow = Mimic.Layers("XXX").Item("Lst_1").Current1stColDataStr
Set Test = Server.Query("INSERT INTO XXX2 (column1, column2, column3) SELECT column1, column2, column3 FROM XXX1 WHERE ID = '" + SelectedRow + "'" + "")
Thanks,
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-10-29 06:54 AM . Last Modified: 2020-10-29 06:55 AM
yeah, looks like it would work. i just ran this on a test datatable and it worked as well. it's more or less the same as what you have.
insert into TestDT (FN,ID,Source,CurrentTime) (SELECT FULLNAME,ID,SOURCE,CURRENTTIME FROM CDBPOINT)
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-11-02 09:51 PM . Last Modified: 2020-11-02 09:59 PM
Hi, it hasn't worked for me.
I am guessing it doesn't have to be CDBPoint does it?
One of the tables is in a different file path / folder structure, does this matter?
Set Note = Server.Query("INSERT INTO WONSP (ID, ET, Mes, User, Priority, Desc, Status, EID, Cat, NoteNo, SID) (SELECT ID, ET, Mes, User, Priority, Desc, Status, EID, Cat, NoteNo, SID FROM WONS")
Must be getting the syntax wrong.
Thanks,
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-11-03 06:38 AM
Folder path shouldn't matter at all. Looks like you're missing a ) in the query syntax. Try the below
Set Note = Server.Query("INSERT INTO WONSP (ID, ET, Mes, User, Priority, Desc, Status, EID, Cat, NoteNo, SID) (SELECT ID, ET, Mes, User, Priority, Desc, Status, EID, Cat, NoteNo, SID FROM WONS)")
Link copied. Please paste this link to share this article on your social media post.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Link copied. Please paste this link to share this article on your social media post.
Posted: 2020-11-03 01:49 PM
Hi, the owner of the source table had not only renamed the table, but also changed the format.
I had asked. Arrrrr.
I had tried a number of syntax combinations previously, which obviously would never have worked.
tfranklin thanks for your help and persistence with it.
It was a big help! I didn't know if what I was trying to do could be done.
I will mark your post as the answer.
Thanks,
Link copied. Please paste this link to share this article on your social media post.

