evaluating statement within a parameter for stored procedure

Is is possible to do something like this? (I don't know what the
proper terminology is... evaluating statement inline??)

exec pr_foo [at] param = 'a' + 'b'
exec pr_foo [at] param = getdate()

I wasn't able to get this to work. I know I can use a local variable
do all the manipulation, then pass the local variable, but I was
wondering if there was a way to do it inline.
bucky3 [ Do, 03 April 2008 20:30 ] [ ID #1934739 ]

Re: evaluating statement within a parameter for stored procedure

bucky3 (bucky3 [at] mail.com) writes:
> Is is possible to do something like this? (I don't know what the
> proper terminology is... evaluating statement inline??)
>
> exec pr_foo [at] param = 'a' + 'b'
> exec pr_foo [at] param = getdate()
>
> I wasn't able to get this to work. I know I can use a local variable
> do all the manipulation, then pass the local variable, but I was
> wondering if there was a way to do it inline.

No, you cannot pass expressions as actual parameters in T-SQL. Only
constants and variables.


--
Erland Sommarskog, SQL Server MVP, esquel [at] sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx
Erland Sommarskog [ Do, 03 April 2008 23:29 ] [ ID #1934743 ]

Re: evaluating statement within a parameter for stored procedure

No, T-SQL is a simple one-pass compiler with strong typing. Your
parameters have to be constants or variables and at least cast-able to
the declared data type.
Joe Celko [ Fr, 04 April 2008 00:43 ] [ ID #1934747 ]

Re: evaluating statement within a parameter for stored procedure

On Apr 3, 1:29 pm, Erland Sommarskog <esq... [at] sommarskog.se> wrote:
> No, you cannot pass expressions as actual parameters in T-SQL. Only
> constants and variables.

OK thanks.
bucky3 [ Fr, 04 April 2008 01:05 ] [ ID #1935511 ]
Datenbanken » comp.databases.ms-sqlserver » evaluating statement within a parameter for stored procedure

Vorheriges Thema: What does it mean to SET a value?
Nächstes Thema: An optimum query..?