Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5945539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:41:46+00:00 2026-05-22T16:41:46+00:00

How do you initialize a variable in a stored procedure with a function? This

  • 0

How do you initialize a variable in a stored procedure with a function?

This doesn’t work:

/****** Object:  StoredProcedure [dbo].[usp_ShowBackpopGaps]    Script Date: 05/25/2011 19:57:23 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[usp_ShowBackpopGaps] 
    -- Add the parameters for the stored procedure here
    @StartDate datetime = DateAdd(yy, -1,getdate()), 
    @EndDate datetime = getdate
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    ;with dateranges as(
                select DateAdd(dd,-1,EtlStartDate) as DateFrom,
                DateAdd(dd,1,EtlEndDate) as DateTo
                from EtlJobRunStatus
                where JobRunStepID like 'ETL[0-9]%' and EndTime is not null
                union all
                select @StartDate ,@StartDate 
                union all
                select DateAdd(dd,-1,@EndDate),DateAdd(dd,-1,@EndDate)    
            )
            select DateAdd(dd,-1,DateTo) as MissingFrom,
              DateAdd(dd,1,NextDateFrom) as MissingTo,
              DateDiff(d,DateTo, NextDateFrom) as MissingDays
            from (
              select distinct DateFrom, DateTo as DateTo, 
                 (select MIN (dateFrom) 
                    from dateranges 
                    where DateTo > D.DateTo
                 ) as NextDateFrom
              from dateranges D
            ) X
            where DateTo < NextDateFrom
END


GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:41:47+00:00Added an answer on May 22, 2026 at 4:41 pm

    You can’t have a function call as a parameter default.

    I think you need

    CREATE PROCEDURE [dbo].[usp_ShowBackpopGaps] 
     @StartDate DATETIME = NULL,      
     @EndDate DATETIME = NULL
    AS 
    BEGIN
    SET @StartDate = ISNULL(@StartDate,DATEADD(yy, -1,GETDATE()))
    SET @EndDate =  ISNULL(@EndDate, GETDATE())
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In C++ you can initialize a variable in an if statement, like so: if
How do I default-initialize a local variable of primitive type in C++? For example
I'm having trouble in getting the singleton pattern to initialize a instance variable in
Does anyone know why a library initialized within dlopen() would initialize a static variable
When we create a variable and don't initialize it, then some (random) number called
I have created an stored procedure in SQL Server 2008 and it contains the
My data is stored in a member variable (NSArray) of a view controller. The
Say I want to store some variable in my controller. I want to initialize
In Ruby, can one object destroy another? For example: class Creature def initialize @energy
how to initialize a variable of data type integer, in C#. the problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.