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 6873389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:03:44+00:00 2026-05-27T04:03:44+00:00

This is my first shot at writing a stored procedure. I’m trying to get

  • 0

This is my first shot at writing a stored procedure. I’m trying to get a list of all orders placed between two dates. I would run this proc monthly, getting the orders for the trailing 6 months. If I ran it on the 2nd or the 15th of the month, it would still take the previous 6 months from the end of the previous month.

Here’s the code:

CREATE PROCEDURE pMonthlyCustomerReport 
    -- Get the last day of the previous month and the first day of 6 months ago
    @enddate date,
    @startdate date
AS
    SET @enddate = DATEADD(D,-1,DATEADD(mm, DATEDIFF(m,0,GETDATE()),0));
    SET @startdate = DATEADD(M, DATEDIFF(MONTH, 0, GETDATE())-6, 0);

    -- Get orders for the past 6 months
    SELECT acct_num, date as OrderDate, type as OrderType
    INTO #Orders
    FROM rders
    WHERE date BETWEEN @startdate AND @enddate;

When I run the proc, I get this error message:

Procedure or function ‘pMonthlyCustomerReport’ expects parameter ‘@enddate’, which was not supplied.

Any suggestions or best practices I should be using here? I may be over-thinking creating the @enddate, @startdate and should just put them in the query, but I want the variable to be declared up front.

Any thoughts?

Thanks

  • 1 1 Answer
  • 2 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-27T04:03:45+00:00Added an answer on May 27, 2026 at 4:03 am

    You can just declare the vars @startdate and @enddate instead of making them parameters to the sp, since you are setting them based on the current date anyway:

    DECLARE @startdate datetime
    DECLARE @enddate datetime
    

    then declare it like this:

    CREATE PROCEDURE pMonthlyCustomerReport 
    AS
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this my first shot at this awesome new (to me) programmers site, I hope
Ok let's first look at a screen shot. This is a screen shot of
i have two arrays like this first array Array ( [0228] => Array (
Using Dozer to map two objects, I have: /** /* This first class uses
I've been developing for Android for awhile but this is my first shot at
I don't have any background in programming and this is my first shot. I
This is the first time I am trying for the SQL Job Agent ...I
I am taking an experimental first shot at writing a simple side-scroller game. I
This is my first shot at brute-forcing the NP-complete knapsack problem . In this
I gave generating test data a first shot by trying to populate my database

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.