Discussion:
insert with values from select
(too old to reply)
mcnewsxp
2012-11-13 21:50:39 UTC
Permalink
i need to pass a single value to a stored proc for a select statement then use a couple of the values in the select statement in an insert statement.

@id as decimal

select a, b, c, d from table1 where id = @id

insert into table2(col1, col2, col3, col4) values (table1.a, table1.b, table1.c, table1.d) where id = @id

i could use help with syntax.

tia,
mcnewsxp
Bob Barrows
2012-11-14 01:12:36 UTC
Permalink
Post by mcnewsxp
i need to pass a single value to a stored proc for a select statement
then use a couple of the values in the select statement in an insert
statement.
@id as decimal
insert into table2(col1, col2, col3, col4) values (table1.a,
i could use help with syntax.
tia,
mcnewsxp
insert into table2(col1, col2, col3, col4)
select a, b, c, d from table1 where id = @id
mcnewsxp
2012-11-14 12:49:42 UTC
Permalink
Post by mcnewsxp
Post by mcnewsxp
i need to pass a single value to a stored proc for a select statement
then use a couple of the values in the select statement in an insert
statement.
@id as decimal
insert into table2(col1, col2, col3, col4) values (table1.a,
i could use help with syntax.
tia,
mcnewsxp
insert into table2(col1, col2, col3, col4)
i kind of worked that out, but now have a problem. the time span part - e.ev_eventend and e.ev_eventend cannot be bound.
mcnewsxp
2012-11-14 12:52:34 UTC
Permalink
Post by mcnewsxp
Post by mcnewsxp
Post by mcnewsxp
i need to pass a single value to a stored proc for a select statement
then use a couple of the values in the select statement in an insert
statement.
@id as decimal
insert into table2(col1, col2, col3, col4) values (table1.a,
i could use help with syntax.
tia,
mcnewsxp
insert into table2(col1, col2, col3, col4)
i kind of worked that out, but now have a problem. the time span part - e.ev_eventend and e.ev_eventend cannot be bound.
had to use my DB first. my bad.
thanks
n***@gmail.com
2012-11-20 07:33:04 UTC
Permalink
Post by mcnewsxp
i need to pass a single value to a stored proc for a select statement then use a couple of the values in the select statement in an insert statement.
@id as decimal
i could use help with syntax.
tia,
mcnewsxp
Generally speaking, the syntax is:

insert into table2(col1, col2, col3, col4)
select a, b, c, d from table1 where id = @id

You shouldn't need to do the select as a separate statement.

Loading...