INSERT INTO table1 ( column1, column2, someInt, someVarChar ) SELECT table2.column1, table2.column2, 8, 'some string etc.'. FROM table2. WHERE table2.ID = 7; I've only used this syntax with Access, SQL 2000/2005/Express, MySQL, and PostgreSQL, so those should be covered. It should also work with SQLite3.
Share, comment, bookmark or report
I now want to INSERT the results of this query into another table. I have tried the following: INSERT INTO tablea(a,b) ;WITH alias (y,z) AS ( SELECT y,z FROM tableb ) SELECT y, z FROM alias but I get the error: Incorrect syntax near ';'. So I have tried without the semicolon but got the error: Incorrect syntax near the keyword 'WITH'.
Share, comment, bookmark or report
I mean something like this: With helper_table As (. Select * From dummy2. ) Insert Into dummy1 Values (Select t.a From helper_table t Where t.a = 'X' ); Thx! My example is too dummy, so I add some extended code (thx for the answers so far). INSERT. INTO dummy values (a,b) //more values.
Share, comment, bookmark or report
2742. In SQL Server 2008 you can insert multiple rows using a single SQL INSERT statement. INSERT INTO MyTable ( Column1, Column2 ) VALUES. ( Value1, Value2 ), ( Value1, Value2 ) For reference to this have a look at MOC Course 2778A - Writing SQL Queries in SQL Server 2008. For example: INSERT INTO MyTable.
Share, comment, bookmark or report
You will want to use the YYYYMMDD for unambiguous date determination in SQL Server. insert into table1(approvaldate)values('20120618 10:34:09 AM'); If you are married to the dd-mm-yy hh:mm:ss xm format, you will need to use CONVERT with the specific style. insert into table1 (approvaldate)
Share, comment, bookmark or report
UPDATE Payments. SET Amount = 12.33. WHERE CustomerID = '145300'. Else if you are trying to insert a new row then you have to use. IF NOT EXISTS(SELECT 1 FROM Payments WHERE CustomerID = '145300') INSERT INTO Payments(CustomerID,Amount) VALUES('145300',12.33) Or if you want to combine both command (if customer exists do update else insert new ...
Share, comment, bookmark or report
2) Another case, if you need to insert same value for all rows(for example, 10 rows you need to insert here). Then you can use below sample statement: INSERT INTO USERS VALUES (2, 'Michael', 'Blythe') GO 10
Share, comment, bookmark or report
INSERT INTO table_name (name, address, tele) SELECT * FROM (SELECT 'Nazir', 'Kolkata', '033') AS tmp WHERE ...
Share, comment, bookmark or report
364. You need to put the CTE first and then combine the INSERT INTO with your select statement. Also, the"AS" keyword following the CTE's name is not optional: bla bla. Please note that the code assumes that the CTE will return exactly four fields and that those fields are matching in order and type with those specified in the INSERT statement.
Share, comment, bookmark or report
In fact, this INSERT seems bound to fail with primary key uniqueness violations. MySQL does not support inserts into multiple tables at the same time. You either need to perform two INSERT statements in your code, using the last insert id from the first query, or create an AFTER INSERT trigger on the primary table.
Share, comment, bookmark or report
Comments