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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:20:32+00:00 2026-05-29T17:20:32+00:00

Hello I have this code I am trying to fix, the issue is that

  • 0

Hello I have this code I am trying to fix, the issue is that when I pass a parameter within the same year say

startDate = 01/01/2011  EndDate 07/01/2011

It works it returns the correct data but the issue is when I try to use it with a different year, say

startDate = 02/01/2011 EndDate 01/25/2012   
--(wont work shows blank all thought there is data in both years).

Here is my sql code

ALTER PROCEDURE [dbo].[GetOrderByDateRange]
    @startDate nvarchar(50),
    @endDate nvarchar(50)
AS
BEGIN
    DECLARE @days varchar(100)
    set @days = DATEDIFF(d, @StartDate, DATEADD(day,+1,@EndDate)) 

    SELECT distinct(CONVERT(char(10), OrdDate, 101)) as OrdDate,
    COUNT(PurchaseId) as OrdCount,
    SUM(Total) as OrdTotals,
    AVG(Total) as AvgOrdAmount,
    SUM(SubTotal) as Net,
    @days as 'Days'
    FROM [PurchaseOrders]
    WHERE CONVERT(char(10), OrdDate, 101) >= @startDate 
      AND CONVERT(char(10), OrdDate, 101) <= @endDate
    GROUP BY CONVERT(char(10), OrdDate, 101) 
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-29T17:20:44+00:00Added an answer on May 29, 2026 at 5:20 pm

    Don’t use CONVERT… assuming OrdDate is a DATETIME column, it should be:

    CREATE PROCEDURE dbo.GetOrderByDateRange
        @StartDate DATE, -- pass 'yyyy-mm-dd' format
        @EndDate   DATE
    AS
    BEGIN
        SET NOCOUNT ON;
    ...
        WHERE OrdDate >= @startDate AND OrdDate < DATEADD(DAY, 1, @endDate)
    END
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have this string: s = '<p>Hello!</p>' When I pass this
Lets say I have this code: <?php class hello { var $greeting = hello;
Suppose I have this code: String encoding = UTF-16; String text = [Hello StackOverflow];
Problem Hello all! I have this code which takes my jpg image loops through
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
I have a C++ DLL with code like this: LogMessage( Hello world ); try
Hello I have this list that i am working on. When i move the
Let's say I have this string: Hello &, how are you? I'm fine! Is
**Hello, I'm trying to create an archiver in java. This means that I am
I have this HTML code: <p>Hello <span class=hide style=display:none>there</span> jquery</p> <button class=toggle>Toggle</button> <p>Hello <span

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.