I need to insert values into a table. But my condition is that I need to select Min(date) from another table and this value should be inserted into another table.
My query
Insert into tempTable values
('Value1','Value2','Value3',(select min(val_dt) from anotherTable),'Y',getdate())
If I use this query I am facing error.
Guide me how to use select query inside the insert query.
Instead of using VALUES() in the INSERT statement, use a SELECT to add the row values:
And the SELECT statement can be as convoluted as you want, meaning WHEREs and the like can be included.