Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 stored proc parameters by number

Author  Topic 

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-08-19 : 04:42:18
is it possible to call a sp with something like @1 = 'foo' ? instead
of the full name of that param ?

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-08-19 : 04:51:33
As far as i know, you cannot call the parameter by the number. You either need to use the parameter name or pass in the same order (without specifying the name).


I am here to learn from Masters and help new bees in learning.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-08-19 : 05:01:58
quote:
Originally posted by doubleotwo

is it possible to call a sp with something like @1 = 'foo' ? instead
of the full name of that param ?


Why do you want to do this?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-08-19 : 05:21:00
You can call a Stored Procedure withoyut ANY parameter names, BUT the parameters MUST be in the right order (and the problem is that that order may change in the future - e.g. if a developer "adds one" or similar). There are also some issues about parameters which are defined with default values - I'm a bit hazzy on that, but it may mean you get a run time error, retrospectively for code that used to work, if you add a Default value to a parameter's definition (i.e. one that used not to have a default)

So, instead of your proposed

EXEC MySproc @1 = 'foo'

you can have

EXEC MySproc @Param1Name = 'foo'

or just

EXEC MySproc 'foo'
Go to Top of Page

doubleotwo
Yak Posting Veteran

69 Posts

Posted - 2010-08-19 : 05:47:53
ow. .. i really tought this was possible..

i want to add my parameters with a .NET program
i got a datatable and want to do some checks on each row

and insert/update according to the check...

but instead of programming each par , i wanted to just create a loop...
now i can rename all the pars of the sp with something like par1 par2 ...

this should fix it :)

thx anyways !
Go to Top of Page
   

- Advertisement -