Solved

stored procedure with optional parameters

Posted on 1998-09-20
1
185 Views
Last Modified: 2010-03-19
i want to build a stored procedure with some parameters, if one ore more of the parameters isn't given then it should not be included in the procedure ( 'and <column name> = 'value' should be ignored ), I know it is possible but i don't know how.
0
Comment
Question by:skysoft
1 Comment
 
LVL 7

Accepted Solution

by:
spiridonov earned 200 total points
ID: 1090204
You do not need to specify parameter if you specify default when you define your stored procedure:
Simple example:
CREATE PROCEDURE test @optional_param varchar(10)="none"
as
IF @optional_param="none"
 SELECT * from t1
ELSE
 SELECT @ from t1
  WHERE col1=@optional_param
IF you have multiple optional parameters you will have to first build your SQL string and then use EXEC to execucte it.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now