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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:38:55+00:00 2026-05-12T11:38:55+00:00

Using SQL Server 2000 My Query. SELECT (Format(IIf(CLng(OutTime) > 180000, CDate(’18:00:00′), CDate(Format(OutTime, ’00:00:00′))) –

  • 0

Using SQL Server 2000

My Query.

SELECT 
  (Format(IIf(CLng(OutTime) > 180000, CDate('18:00:00'),  CDate(Format(OutTime, '00:00:00'))) - IIf(CLng(InTime) < 90000,  CDate('09:00:00'), CDate(Format(InTime, '00:00:00'))), 'hh:nn:ss')) As WorkTime, 
  (Format(IIf(CLng(InTime) < 90000, CDate('09:00:00') -  CDate(Format(InTime, '00:00:00')), 0) + IIf(CLng(OutTime) > 180000,  CDate(Format(OutTime, '00:00:00')) - CDate('18:00:00'), 0), 'hh:nn:ss')) As OverTime 
FROM table

Above query is Access Query, I want to write a same query in sql.

Condition.

I want to Calculate the time after 090000(HH:MM:SS) before 180000 comes in worktime, before
090000 after 180000 comes in overtime.

Intime, Outime data type is varchar in the database

Am new to SQL Server 2000

How to write a SQL query from the above same?

  • 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-12T11:38:55+00:00Added an answer on May 12, 2026 at 11:38 am

    Here is literally translated query to TSQL 2000.
    Although, it could be rewritten for better performance:

    Select Convert(char(8),
               case when DateAdd(Day,-DateDiff(Day, 0, OutTime), OutTime)>'18:00:00' 
                    Then Cast('18:00:00' as datetime) 
                    Else DateAdd(Day,-DateDiff(Day, 0, OutTime), OutTime) 
               End 
               - 
               Case when DateAdd(Day,-DateDiff(Day, 0, InTime),  InTime) <'09:00:00' 
                    Then Cast('09:00:00' as datetime) 
                    Else DateAdd(Day,-DateDiff(Day, 0, InTime),  InTime) 
               End, 
               8
              ) as WorkTime,
       Convert(char(8),
               Case when DateAdd(Day,-DateDiff(Day, 0, InTime),  InTime) <'09:00:00' 
                    Then Cast('09:00:00' as datetime) - 
                         DateAdd(Day,-DateDiff(Day, 0, InTime),  InTime)
                    Else Cast('00:00:00' as datetime) 
               End 
               + 
               case when DateAdd(Day,-DateDiff(Day, 0, OutTime), OutTime)>'18:00:00' 
                    Then DateAdd(Day,-DateDiff(Day, 0, OutTime), OutTime) - 
                         Cast('18:00:00' as datetime) 
                    Else Cast('00:00:00' as datetime) 
               End, 
               8
              ) as OverTime
    From Table
    

    Added later:

    If InTime and OutTime have time part only (Date part is Jan 1 1900) you can use directly InTime and OutTime. Otherwise you have to extract time part from datetime column, as:

      DateAdd(Day,-DateDiff(Day, 0, OutTime),  OutTime)
    

    (this is the fastest way to get time part only)

    Instead of:

       DateAdd(Day,-DateDiff(Day, 0, OutTime), OutTime)>'18:00:00'
    

    You can use

       Datepart(hh,OutTime)>17
    

    P.S. as your time is stored as string yoiu don’t need to get time part only. You can cast them to datetime, or you can write also

     cast(left(inTime,2) as int) < 9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 226k
  • Answers 226k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using a Map<Integer, Integer> should be simple as: int mostFrequent(int...… May 13, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer If you have the possibility, better change your database schema… May 13, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer See this link. The idea is to add your MySQL… May 13, 2026 at 1:16 am

Related Questions

Using SQL Server 2000 My Query. SELECT (Format(IIf(CLng(OutTime) > 180000, CDate('18:00:00'), CDate(Format(OutTime, '00:00:00'))) -
Using SQL Server 2000 How to avoid the duplicate values? Query SELECT DISTINCT Modification.dbo.Reference.Dates
Using SQL server 2000. If the Start date is 06/23/2008 and End date is
Using SQL Server 2000 Table1 ID Name, Date, TimeIn, TimeOut, DateIn, Dateout AEAA00294 Alexander
I am using SQL Server 2000. I am writing a trigger that is executed

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.