Solved

Default Option For Stored Procedure With IF - ELSE  Condition

Posted on 2011-03-21
3
202 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
  • 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
create an aggregate function 9 34
Sql server, import complete table, using vb.net 9 34
SQL - Update field defined as Text 6 16
sql server service accounts 4 25
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

773 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