Showing posts with label books. Show all posts
Showing posts with label books. Show all posts

Saturday, February 25, 2012

column reference as parameter of sp

Is it possible to have a column reference as the parameter of a stored
procedure? The books say parameters have to be literal expressions, so
I'm guessing it's not possible, but I thought I'd ask anyway.
I want to do something like this:
INSERT INTO Table1 ([Column1]) (SELECT ? FROM Table2)
The single, unnamed input parameter needs to be the name of one of the
columns in Table2, such as [Column2]. I want it to be a stored
procedure because the query must run many times with alternating column
references and literals.
ShaileshEither
exec a string, or look at using sp_executesql... either will work... both
are doc'd in books on line.
"Shailesh Humbad" <humbads1@.hotmail.com> wrote in message
news:FrmYa.246417$BA.59826426@.twister.columbus.rr.com...
> Is it possible to have a column reference as the parameter of a stored
> procedure? The books say parameters have to be literal expressions, so
> I'm guessing it's not possible, but I thought I'd ask anyway.
> I want to do something like this:
> INSERT INTO Table1 ([Column1]) (SELECT ? FROM Table2)
> The single, unnamed input parameter needs to be the name of one of the
> columns in Table2, such as [Column2]. I want it to be a stored
> procedure because the query must run many times with alternating column
> references and literals.
> Shailesh
>