I want to do something like
insert into my table (select * from anothertable where id < 5)
What is the correct MSSQL syntax?
Thank!
Is this what you are looking for?
INSERT INTO MyTable SELECT * FROM AnotherTable WHERE AnotherTable.ID < 5
This syntax looks correct, but you must match the fields, otherwise it will not work.
You can specify fields, for example:
INSERT INTO myTable(COL1, COL2, COL3) SELECT COL1, COL2, COL3 FROM anotherTable where anotherTable.id < 5
Insert Into MyTable ( Col1, Col2, Col3 ) Select Col1, Col2, Col3 From AnotherTable Where ID < 5
You can also do
select * into MyTable from AnotherTable where ID < 5
which will create MyTable with the necessary columns, as well as fill in the data.
Source: https://habr.com/ru/post/1698536/More articles:Manipulating strings in MS SQL Server - stringtf-idf and previously invisible terms - algorithmDetection of duplicate music files - mp3What is the point of the garbage collector - garbage-collectionHow to create Delphi TSpeedButton or SpeedButton in C # 2.0? - c #JQuery inserts a layer on top of existing content - jqueryПриложение mdi с несколькими потоками графического интерфейса - multithreadingCan someone help explain this diagram - lispCan I use GNU Aspell for English in my asp.net application? - c #Does the asp.net account password write the password field? - loginAll Articles