Combining | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive


Hi, help me please..
How can i combine some statement..I want make in stor procedure Insert with use Select and some value from procedure. Example :
declare @number1 int
set @number1 =100 set @sqlCommand = ‘ INSERT Report (Col1,TExt1)
values( Select d.col1, @number1 ) from Detail D
order by d.col1′ In table Report is column Col1. I want to insert all records from column COL1(or sum it ) from table Detail -> Report and insert in this statement value @number from stored procedure. Thanks, Lubo
You almost have it! DECLARE @number1 int
SET @number1 =100 INSERT INTO Report(Col1, Text1)
SELECT d.Col1, @number1
FROM Detail d
You dont even need to use dynamic query to insert. You can use this query too. INSERT Report
SELECT col1,100 FROM Detail