Results 1 to 3 of 3

Thread: [RESOLVED] Can we Test if a parameter isnt been Given to a Stored Procedure

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Resolved [RESOLVED] Can we Test if a parameter isnt been Given to a Stored Procedure

    Hello,

    let's say i have a stored procedure that has a parameter input
    i am talking on SQL Server 2000 (No relation about Ado.Net)

    can i test if a parameter isnt been given
    & show a message ?


    Thanks !
    Last edited by killer7k; Jun 10th, 2008 at 04:41 AM.

  2. #2
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Can we Test if a parameter isnt been Given to a Stored Procedure

    You can give the parm a default value of Null and then test it's value isn't null within the sproc:-

    Code:
    Create Procedure MadeUp
    @Parm as varchar(50) = null
    As 
    Begin
       If @Parm is null then
          Select 'Parm Not Received'
       Else
          Select 'Parm Received OK'
    End

    That won't distinguish between the parm not being passed and it being explicitely passed as a null though. If you need to distinguish between those two states I guess you could set its default value to something really unlikely to occur and then test for that instead - that's a bit messy though.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: Can we Test if a parameter isnt been Given to a Stored Procedure

    Quote Originally Posted by FunkyDexter
    You can give the parm a default value of Null and then test it's value isn't null within the sproc:-

    Code:
    Create Procedure MadeUp
    @Parm as varchar(50) = null
    As 
    Begin
       If @Parm is null then
          Select 'Parm Not Received'
       Else
          Select 'Parm Received OK'
    End

    That won't distinguish between the parm not being passed and it being explicitely passed as a null though. If you need to distinguish between those two states I guess you could set its default value to something really unlikely to occur and then test for that instead - that's a bit messy though.
    Yep m8 Thanks , I made the samething but forgot to give the parm a default value of Null

    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width