Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
2
Answers
How to find Check current time is in break or not?
Atul Patil
5y
724
1
Reply
Table Name - Shift
CREATE
TABLE
[dbo].[shift](
[shift_id] [
int
] IDENTITY(1,1)
NOT
NULL
,
[shift_name] [
varchar
](50)
NULL
,
[from_time] [datetime]
NULL
,
[to_time] [datetime]
NULL
,
[added_by] [
int
]
NULL
,
[modified_by] [
int
]
NULL
,
[added_on] [datetime]
NULL
,
[modified_on] [datetime]
NULL
,
[is_active] [
bit
]
NULL
,
[venue_id] [
int
]
NULL
,
CONSTRAINT
[PK__shift__7B267220887FF64E]
PRIMARY
KEY
CLUSTERED
(
[shift_id]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
GO
Table Name - Rel Shift break Schedule
CREATE
TABLE
[dbo].[rel_shift_break_schedule](
[break_id] [
int
] IDENTITY(1,1)
NOT
NULL
,
[break_name] [
varchar
](250)
NULL
,
[break_start_time] [datetime]
NULL
,
[break_end_time] [datetime]
NULL
,
[venue_id] [
int
]
NULL
,
[shift_id] [
int
]
NULL
,
[zone_id] [
int
]
NULL
,
[added_by] [
int
]
NULL
,
[added_on] [datetime]
NULL
,
[modified_by] [
int
]
NULL
,
[modified_on] [datetime]
NULL
,
[is_active] [
bit
]
NULL
,
PRIMARY
KEY
CLUSTERED
(
[break_id]
ASC
)
WITH
(PAD_INDEX =
OFF
, STATISTICS_NORECOMPUTE =
OFF
, IGNORE_DUP_KEY =
OFF
, ALLOW_ROW_LOCKS =
ON
, ALLOW_PAGE_LOCKS =
ON
)
ON
[
PRIMARY
]
)
ON
[
PRIMARY
]
GO
Question - Each shift have multiple breaks. So, how to check current time is in break or not. Result is return True or False. Following is my running query, its working perfect, but i dont want to use WHILE LOOP because of permormance impact. So please suggest me a better option over WHILE LOOP.
DECLARE
@shift_id
INT
= 65
DROP
TABLE
#shiftListCnt
CREATE
TABLE
#shiftListCnt(
ID
INT
IDENTITY(1, 1),
shift_id
INT
,
break_start_time DATETIME,
break_end_time DATETIME
)
INSERT
INTO
#shiftListCnt
SELECT
shift_id, break_start_time,break_end_time
FROM
rel_shift_break_schedule
WHERE
shift_id = @shift_id
AND
is_active = 1
DECLARE
@check_time_hr_int
AS
FLOAT
,
@boundry_from_time_hr_int
AS
FLOAT
,
@boundry_to_time_hr_int
AS
FLOAT
,
@result
AS
INT
,
@check_time
VARCHAR
(10);
DECLARE
@inirow
INT
= 1;
DECLARE
@NumberofRowint
INT
;
DECLARE
@venue_id
INT
;
DECLARE
@boundry_from_time
VARCHAR
(10),
@boundry_to_time
VARCHAR
(10);
SELECT
@venue_id = venue_id
FROM
rel_shift_break_schedule
WHERE
shift_id = 65
SET
@NumberofRowint = (
select
COUNT
(*)
from
#shiftListCnt)
SET
@check_time =
CAST
(dbo.fnGetAirportDate(@venue_id)
AS
TIME
)
-- VENUE TIME
SELECT
@check_time venue_time, @NumberofRowint
While @inirow <= @NumberofRowint
BEGIN
SET
@boundry_from_time =
CAST
((
SELECT
break_start_time
FROM
#shiftListCnt
WHERE
ID=@inirow)
AS
TIME
)
SET
@boundry_to_time =
CAST
((
SELECT
break_end_time
FROM
#shiftListCnt
WHERE
ID=@inirow)
AS
TIME
)
SET
@check_time_hr_int =
CONVERT
(
DECIMAL
(10, 2),
CONVERT
(
FLOAT
, DATEDIFF(
MINUTE
, 0, @check_time))) / 60;
-- IF (@check_time_hr_int < 1)
-- BEGIN
-- -- SET @check_time_hr_int += 24;
-- END
SET
@boundry_from_time_hr_int =
CONVERT
(
DECIMAL
(10, 2),
CONVERT
(
FLOAT
, DATEDIFF(
MINUTE
, 0, @boundry_from_time))) / 60;
SET
@boundry_to_time_hr_int =
CONVERT
(
DECIMAL
(10, 2),
CONVERT
(
FLOAT
, DATEDIFF(
MINUTE
, 0, @boundry_to_time))) / 60;
IF (@boundry_from_time_hr_int > @boundry_to_time_hr_int)
BEGIN
SET
@boundry_to_time_hr_int += 24;
IF (@check_time_hr_int <= 12
AND
@boundry_from_time_hr_int > 12)
BEGIN
SET
@check_time_hr_int += 24;
END
END
IF (@check_time_hr_int >= @boundry_from_time_hr_int
AND
@check_time_hr_int <= @boundry_to_time_hr_int)
BEGIN
SET
@result = 1;
END
ELSE
BEGIN
SET
@result = 0;
END
SET
@inirow = @inirow + 1;
END
SELECT
@result status
--RETURN @result;
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
how to use multiple database at same time
How to use Nolock in SQL server