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 2005 Forums
 Transact-SQL (2005)
 Another Param Depending of the First Param value

Author  Topic 

CVDpr
Starting Member

41 Posts

Posted - 2008-10-30 : 11:17:54
Hey there, when i run this sp_sel_MntInstruments_Sel it ask me for @what and @samplenumber. its there a way to only ask for @samplenumber when @what = 'samplenumber'? thanks.


create procedure sp_sel_MntInstruments_Sel

@what as varchar(15),
@samplenumber as bigint

as
begin

if @what = 'subdept'
select deptid, subdeptid, description from MstSubDept with(nolock) where deptid = 2 order by description

if @what = 'instrument'
select InstrumentId, dbo.fn_ProperCase(InstrumentName) as "InstrumentName" from MstLabInstrument with(nolock) order by InstrumentId

if @what = 'samplenumber'
select a.SampleNumber, a.InstrumentId , a.CdmDesc , a.FirstName +' '+ a.MiddleName +' '+ a.LastName1 + ' '+ a.LastName2
from AppLabSenderQueueHST a with(nolock) where a.SampleNumber = @samplenumber
end

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-10-30 : 11:52:52
Try this:
exec sp_sel_MntInstruments_Sel 'subdept', null
exec sp_sel_MntInstruments_Sel 'instrument', null
exec sp_sel_MntInstruments_Sel 'samplenumber', <your_number>

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-30 : 12:33:42
and if you set default value of parameter as null you dont have to explicitly pass it too. you can just use

exec sp_sel_MntInstruments_Sel 'subdept'
exec sp_sel_MntInstruments_Sel 'instrument'...


you need to do like this


create procedure sp_sel_MntInstruments_Sel

@what as varchar(15),
@samplenumber as bigint=null
...

Go to Top of Page

CVDpr
Starting Member

41 Posts

Posted - 2008-10-30 : 14:26:29
Yes @samplenumber as bigint=null, Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-30 : 14:30:15
quote:
Originally posted by CVDpr

Yes @samplenumber as bigint=null, Thanks



cheers
Go to Top of Page
   

- Advertisement -