Solved

how to assign default value to a parameter

Posted on 2014-09-08
1
145 Views
Last Modified: 2014-09-08
I need to set a default value to the the following parameters in my SQL query so that I do not have to pass them in via a form.
@gbloptState AS VARCHAR(4) ,   = 4-
@InsPrfCrdLtrOpt AS VARCHAR(1) = 1

Query

USE [EXPORTmdhpixPROD]
GO
/****** Object:  StoredProcedure [dbo].[InsProfile_CredLetter_Parm]    Script Date: 9/8/2014 8:49:17 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
/* ***************************************************************************************************/
/*              Insured Profile & Credentialing Letter                                                              */
/* **************************************************************************************************/

ALTER PROCEDURE [dbo].[InsProfile_CredLetter_Parm]
    (
      @gbloptState AS VARCHAR(4) ,
      @InsPrfCrdLtrOpt AS VARCHAR(1)
    )

AS
    SET NOCOUNT ON
    SELECT DISTINCT
            IC.LicenseNumber AS [License Nbr] ,
            RM.City AS City ,
            RM.State AS state ,
            RM.Zip AS zip ,
            Insured ,
            IC.GroupName AS GroupFirmName ,
            SUBSTRING(IC.Policy, 1, CHARINDEX('-', IC.Policy)) AS PolPrefix ,
            RM.Addr1 ,
            RM.Addr2 ,
            RM.Addr3 ,
            RM.Fax ,
            InsuredName = CASE WHEN RM.FirstName = ' ' THEN RM.LastName
                               ELSE RM.FirstName + ' '
                                    + CASE WHEN ISNULL(RM.MiddleInitial, ' ') = ' '
                                           THEN RM.LastName + ' '
                                           ELSE RM.MiddleInitial + ' '
                                                + RM.LastName + ' '
                                      END
                                    + CASE WHEN ISNULL(RM.Title, ' ') = ' '
                                           THEN RM.Designation
                                           ELSE RM.Title + ' '
                                                + RM.Designation
                                      END
                          END
    FROM    InsuredCov_All IC
            INNER JOIN wellandp.ReferMaster RM ON 'A' + IC.LicenseNumber = RM.ReferKey
    WHERE   ( LEFT(RM.ReferKey, 1) = 'A' )
            AND ( IC.SlotType <> 'S' )
            AND ( dbo.IsTail(IC.RiskType) = 'N' )
            AND ( @gbloptState LIKE '%99%'
                  OR SUBSTRING(IC.Policy, 1, CHARINDEX('-', IC.Policy)) = @gbloptState
                )
            AND ( ( @InsPrfCrdLtrOpt = '1' )
                  OR ( @InsPrfCrdLtrOpt = '2'
                       AND dbo.IsEPLI(IC.RiskType) = 'N'
                     )
                )
    ORDER BY insured
0
Comment
Question by:mburk1968
1 Comment
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40309910
Just set the value that you want in the parameter definition:

ALTER PROCEDURE [dbo].[InsProfile_CredLetter_Parm]
     (
       @gbloptState AS VARCHAR(4)  = '4',
       @InsPrfCrdLtrOpt AS VARCHAR(1) = '1'

.
.
.

Open in new window

0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 2012 - Merge Replication Issue 1 22
Need help how to find where my error is in UFD 6 30
SQL view 2 27
SSAS Hierarchy with columns with folder names 10 14
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

777 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