all groups > sql server programming > october 2006 >
You're in the

sql server programming

group:

Undefined at compile time number of parameters


Re: Undefined at compile time number of parameters Erland Sommarskog
10/31/2006 3:43:21 PM
sql server programming:
ggeshev (ggeshev@tonegan.bg) writes:
[quoted text, click to view]

I'm afraid that you are not in Kansas anymore.

I don't really know what you want to do, but look at an article of
mine for ideas: http://www.sommarskog.se/arrays-in-sql.html.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Undefined at compile time number of parameters ggeshev
10/31/2006 5:27:03 PM
Hello!

I would like to implement a stored procedure as a CLR one.

CREATE PROCEDURE MultiParamSP (
@a nvarchar(100) = '',
@b nvarchar(100) = '',
[..., n]
)
AS
EXTERNAL NAME ...;

I would like MultiParamSP to support undefined at compile time number of
nvarchar(100)
parameters.

It's easy to declare the corresponding method in C# code :
public static void MultiParamSP (params string[] str)
{
//
}

But what should the "CREATE PROCEDURE MultiParamSP" script looks like when
it is time

to declare the parameters?

Re: Undefined at compile time number of parameters ggeshev
11/1/2006 12:00:00 AM
[quoted text, click to view]


Thank you for the article, Erland!

But I need a solution to the question exactly as I defined it!

Look, in many, really many existng T-SQL stored procedures I have calls to
the MultiParamSP in the various forms:
exec MultiParamSP 'aa', 'bb'
or
exec MultiParamSP 'aa', 'bb', 'cc'
or
exec MultiParamSP 'aa', 'bb', 'cc', 'dd'

Now MultiParamSP has no fixed number of VARCHAR(100) parameters, because it
is implemented as an extended stored procedure and the declaration is as
follows :

EXEC sp_addextendedproc MultiParamSP, 'MultiParamSP.dll'.
As you see this way of declaration does not fix the number of parameters the
SP receives.

Now with MSSQL Server 2005 I would like to throw away this "extended SP" way
of doing this because Microsoft announce a wish to leave off extended stored
procedures.
So I wish to implement the same MultiParamSP stored procedure as a CLR one.
And the main idea is NOT TO CHANGE THE SOURCE OF THE T-SQL STORED PROCEDURES
WHICH CALL MultiParamSP.
So the calls should remain :
exec MultiParamSP 'aa', 'bb'
or
exec MultiParamSP 'aa', 'bb', 'cc'
or
exec MultiParamSP 'aa', 'bb', 'cc' 'dd'.

Thank you, Erland!

Re: Undefined at compile time number of parameters Erland Sommarskog
11/1/2006 12:00:00 AM
ggeshev (ggeshev@tonegan.bg) writes:
[quoted text, click to view]

Unfortunately, there is no way out. If you want to replace the XP with a
CLR, you will need to find a new interface for it. Or implement your
CLR procedure with 20 parameters, or whatever is the maximum number of
parameters specified in a call to the XP today.

....but since extended stored procedures reside in master, I guess you will
need to change the calls anyway to remove the "master.." stuff.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: Undefined at compile time number of parameters Dave Frommer
11/1/2006 12:00:00 AM
I think what Erland was saying is. You can't do that with CLR stored
procedures. As far as I know, they must have a pre-determined number of
parameters, though, some or all of them can be optional.


[quoted text, click to view]

Re: Undefined at compile time number of parameters ggeshev
11/1/2006 12:00:00 AM

[quoted text, click to view]

Thank you Erland!
This is a definite answer.
Nevertheless you say it is impossible, I needed to know that for sure.
And you are quite right for the calling convention "EXEC
master.dbo.ExtendedSP" is a thing I didn't guessed of.
Thank you very much!

AddThis Social Bookmark Button