Solved

Default Option For Stored Procedure With IF - ELSE  Condition

Posted on 2011-03-21
3
204 Views
Last Modified: 2013-11-05
I need to set a default for the stored procedure to begin automatically at type if no value is supplied -    Right now you need to specify 0 for the type condition to begin -----    So Basically the default will automatically check the IF(@Type=0) Condition and maybe a 1 or something else will skip that condition Completely - Any help will be appreciated

CREATE PROCEDURE Report].[Report2]
      
      @StartDate datetime,
      @EndDate datetime,
                @Type tinyint
AS

BEGIN

set transaction isolation level read uncommitted;

                declare @Type tinyint
      declare @pStartDate datetime
      declare @pEndDate datetime
      declare @IsMonthlyReport bit
                set @Type =0
      set @pStartDate = @StartDate
      set @pEndDate = @EndDate

      
      
       

      BEGIN TRY

            set @IsMonthlyReport = [CoRegReport].[rpt_IsMonthlyReport] (@pStartDate, @pEndDate)
       
       
       
       IF(@Type= 0)
       BEGIN
   
            
            
            
       IF (@IsMonthlyReport = 0)
            BEGIN
0
Comment
Question by:dlrickman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35184341
Hi,
This should help you.

CREATE PROCEDURE Report].[Report2]
      
      @StartDate datetime,
      @EndDate datetime,
                @Type tinyint = 0
AS

Open in new window

0
 

Author Comment

by:dlrickman
ID: 35184448
okay but how do you get @Type to Begin as a default if no input parameter is specified
0
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 500 total points
ID: 35186874
JUST do not pass anything  to @Type

You will call the sproc like this (i.e SPROC NAME: Report2):
EXEC Report2 @StartDate = GETDATE(), @EndDate = GETDATE()

And that's all.

Just to clarify - you need to call a sproc which will have one optional parameter where if not passed it will have 0 as default. Did I understood correctly? or you meant something else?
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
push and Pull replication 31 48
help converting varchar to date 14 25
Regarding Disk IO 3 50
Need to find substring in SQL 3 15
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

730 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