Compare two dates from table Dynamics

Sv1N2S
Member Posts: 13
in SQL General
I'm having problem with my little task. I have a table with information about two users who are working during this time. If this time intersect I need get a MESSAGE/ERROR about it. Can you explain how to do this? Thanks!!

0
Best Answer
-
Use 2 Date records (virtual table).
Do a setrange on both with data from each user, if the both return NOT ISEMPTY you have your error.
Please give us the code. I don't get this sorry.
Those things can drive me crazy. But I like such competitions.
I have a quite complicated way. BUT there MUST be an easier way.TestUserEntry.RESET; TestUserEntry.SETFILTER("Entry No.",'<>%1',"Entry No."); TestUserEntry.SETRANGE(UserID,UserID); TestUserEntry.SETFILTER("Starting Date",'<=%1',"Starting Date"); TestUserEntry.SETFILTER("Ending Date",'>=%1',"Starting Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Starting Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'>=%1',"Starting Date"); TestUserEntry.SETFILTER("Ending Date",'<=%1',"Starting Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Starting Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'>=%1',"Ending Date"); TestUserEntry.SETFILTER("Ending Date",'<=%1',"Ending Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Ending Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'<=%1',"Ending Date"); TestUserEntry.SETFILTER("Ending Date",'>=%1',"Ending Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Ending Date not correct. Existing Entry %1',TestUserEntry."Entry No.");
5
Answers
-
Use 2 Date records (virtual table).
Do a setrange on both with data from each user, if the both return NOT ISEMPTY you have your error.
Please give us the code. I don't get this sorry.
Those things can drive me crazy. But I like such competitions.
I have a quite complicated way. BUT there MUST be an easier way.TestUserEntry.RESET; TestUserEntry.SETFILTER("Entry No.",'<>%1',"Entry No."); TestUserEntry.SETRANGE(UserID,UserID); TestUserEntry.SETFILTER("Starting Date",'<=%1',"Starting Date"); TestUserEntry.SETFILTER("Ending Date",'>=%1',"Starting Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Starting Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'>=%1',"Starting Date"); TestUserEntry.SETFILTER("Ending Date",'<=%1',"Starting Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Starting Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'>=%1',"Ending Date"); TestUserEntry.SETFILTER("Ending Date",'<=%1',"Ending Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Ending Date not correct. Existing Entry %1',TestUserEntry."Entry No."); TestUserEntry.SETFILTER("Starting Date",'<=%1',"Ending Date"); TestUserEntry.SETFILTER("Ending Date",'>=%1',"Ending Date"); IF TestUserEntry.FINDFIRST THEN ERROR('Ending Date not correct. Existing Entry %1',TestUserEntry."Entry No.");
5 -
I don't know if I get the task, but if Name, Date Start and Date Finish are the primary key of that table, the error will occur automatically when the same user will have the same start and end date twice.0
-
just imagine you can not post a date twice AND you can not have a starting date between another timespan. Then you have to do a check like mine above0
-
thanks for helping0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions