Home > Archive > microsoft.public.sqlserver.server > November 2002 > Passing Values To A Stored Procedure





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Passing Values To A Stored Procedure
Miguel

2002-11-11, 12:23 pm

Try this,

CREATE PROCEDURE spPaySlip
@loc varchar(50),
@locname varchar(30) = null
AS
SELECT...........WHERE..........


Can you help with my post of concurrency problem?

Miguel


>-----Original Message-----
>Consider the following stored procedure code snippet:
>
>CREATE PROCEDURE spPaySlip
> @loc varchar(50)
>AS
>SELECT...........WHERE..........
>
>The variable @loc can be either 'allloc' or 'selloc'. If

the value is 'selloc', then another input parameter should
be passed to the procedure which means that apart from the
variable @loc, there will be a 2nd variable, say @locname,
as well. The 2nd variable, @locname, will not be needed if
the value of @loc is 'allloc'. So if the stored procedure
is framed as follows:
>
>CREATE PROCEDURE spPaySlip
> @loc varchar(10),
> @locname varchar(200)
>AS
>SELECT...........WHERE..........
>
>& the above procedure is executed in the Query Analyzer

using
>
>EXEC spPaySlip 'selloc','New York'
>
>there's no problem but as I have said before, if 'allloc'

is passed to the variable @loc, then the variable @locname
will not be needed. So how do I execute the stored
procedure if I am passing 'allloc' to the variable @loc
since if I do the following
>
>EXEC spPaySlip 'allloc'
>
>an error will be thrown since the variable @locname

expects a value? One way this can be done is like this
>
>EXEC spPaySlip 'allloc',''
>
>but is there any other way by which I can "tell" the

procedure that if 'allloc' is passed, then do not expect
any value for the variable @locname but if 'selloc' is
passed, expect a value for the variable @locname?
>
>Thanks,
>
>Arpan
>

Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net