Solved

Set Optional to the Parameters in Sproc

Posted on 2002-04-25
2
332 Views
Last Modified: 2008-03-03
I would like to know whether we can set the parameter in Sproc to be an optional. The values that passed from VB or Access to the sproc can be ignore when this option has been set. Like in Vb or VBA, the function that we create or declare can define the variables either optional or compulsory. Does anyone know this?????

0
Comment
Question by:jetyun
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
Comment Utility
CREATE PROC yourproc
  @mandatory varchar(10),
  @optional int = NULL
AS
  SELECT @mandatory, @optional
GO

try usage:
EXEC yourproc 'testing', 10
EXEC yourproc 'testing'
EXEC yourproc ----> error, proc expects value for parameter @mandatory

CHeers
0
 

Author Comment

by:jetyun
Comment Utility
cool ..i got it..thankx
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

771 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