sp with one or more input parameters

  • Hi,

    I've been tasked with creating a stored procedure which will be executed after a user has input one or more parameters into some search fields. So they could enter their 'order_reference' on its own or combine it with 'addressline1' and so on.

    What would be the most proficient way of achieving this?

    I had initially looked at using IF, TRY ie:

    IF @SearchField= 'order_reference'

    BEGIN TRY

    select data

    from mytables

    END TRY

    However I'm not sure this is the most efficient way to handle this.

    Thanks for any advice

  • This sounds like a 'catch-all' query and can be achieved with dynamic SQL.

    Have a look at the below for an excellent description and examples:

    http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/

  • That looks like it will do the trick! Thank you!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply