Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84248members
353348posts

SQL Insert into table

EcoStruxure Geo SCADA Expert Forum

Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.

Solved
DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
6
1571

SQL Insert into table

Hi,
can I use 

 

INSERT INTO table2
SELECT * FROM table1
WHERE condition;

 

Or is there some other method?

 

Thanks,

 

 

 

 


Accepted Solutions
tfranklin
Lt. Commander
Lt. Commander
0 Likes
5
1560

Re: SQL Insert into table

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.

See Answer In Context

6 Replies 6
tfranklin
Lt. Commander
Lt. Commander
0 Likes
5
1561

Re: SQL Insert into table

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.

DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
4
1548

Re: SQL Insert into table

@tfranklin 

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,

tfranklin
Lt. Commander
Lt. Commander
0 Likes
3
1520

Re: SQL Insert into table

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)

DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
2
1493

Re: SQL Insert into table

@tfranklin

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,

tfranklin
Lt. Commander
Lt. Commander
0 Likes
1
1476

Re: SQL Insert into table

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)")

DavidSkilbeck
Lt. Commander
Lt. Commander
0 Likes
0
1467

Re: SQL Insert into table

@tfranklin 

 

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,