?
Solved

Default Option For Stored Procedure With IF - ELSE  Condition

Posted on 2011-03-21
3
Medium Priority
?
208 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 2000 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

650 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