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

  • Home
  • SEARCH
  • 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 3599320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:21:11+00:00 2026-05-18T20:21:11+00:00

This is my code. declare @dt datetime; declare @AddTime int; declare @earliestTime int; declare

  • 0

This is my code.

declare @dt datetime;
declare @AddTime int;
declare @earliestTime int;
declare @latestTime int;
declare @basedTime int;

set @dt = cast('01-01-1980 00:00:00' as datetime)
select @earliestTime = min(DATEDIFF(MINUTE, @dt, starttime)) from visit
select @latestTime = max(DATEDIFF(MINUTE, @dt, starttime)) from visit
set @AddTime = 30;
set @basedTime = @earliestTime;
set @earliestTime = @earliestTime + @AddTime;

SELECT
    count(DATEDIFF(MINUTE, @dt, starttime)) as 'Ticket Issued',
    @earliestTime as 'Period',
    count(DATEDIFF(MINUTE, @dt, nexttime)) as 'Called Tickets',
    SUM(case when DATEDIFF(second, starttime, nexttime) <= 900 then 1 else 0 end)
        as 'Less than Accepted Waiting Time'
    from visit
    where DATEDIFF(MINUTE, @dt, starttime)between @basedTime and @earliestTime

What I want is.. I want to do the query again and again till @earliestTime > @latestTime

I know I am supposed to use stored procedure.. But I am not sure how to use that..

  • 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-18T20:21:11+00:00Added an answer on May 18, 2026 at 8:21 pm

    try this

    create table #temp TicketIssued numeric(9), Period datetime,
    CalledTickets numeric(9), LessThanAcceptedWaitingTime numeric(9);
    
    while(@earliestTime > @latestTime)
    begin
    set @earliestTime=@earliestTime+@AddTime;
    insert into #temp
    (SELECT 
    count(DATEDIFF(MINUTE, @dt, starttime)) as 'Ticket Issued',
    @earliestTime as 'Period',
    count(DATEDIFF(MINUTE, @dt, nexttime)) as 'Called Tickets',
    SUM(case when DATEDIFF(second, starttime, nexttime) <=900 then 1 else 0 end) as 'Less than Accepted Waiting Time'
    from visit
    where DATEDIFF(MINUTE, @dt, starttime)between @basedTime and @earliestTime)
    end
    
    select * from #temp
    

    hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my code. declare @dt datetime; declare @AddTime int; declare @earliestTime int; declare
This SQL Server 2005 T-SQL code: DECLARE @Test1 varchar; SET @Test1 = 'dog'; DECLARE
I am wacking my head over the problem with this code. DECLARE @root hierarchyid
I have a Func in my code that's declared like this: Func<string, int, bool>
I have the following code: DECLARE @monthPassed VARCHAR(MAX) SET @monthPassed = '2010' DECLARE @yearPassed
i meet a code like this, it seem use declare -i to declare variable
Here is the code: declare @allcounterids varchar(max), @counteridquery varchar(max); select @allcounterids = stuff(( select
I can't get this code to work. Declared playpauseButton just above the given below
This code below allows me to find the word error in all my files
This code is the core of a much larger script that works great in

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.