Hi all,
For those of you who remember me from last week's post, I'm STILL trying to figure out what the heck my predecessor was thinking when he wrote this SQL query, among a variety of others:
Okay, A: BEGIN, END, START AND STOP are all reserved words. I'm unfamiliar with the practice of using them as...table names? BEGIN, incidentally, is not a table name listed in vTime_Entries, the view that this view queries.
and B: How is it that you can have 23 BEGINs and, like, 7 ENDs?
and C: Any idea what kind of WYSIWYG this guy used to get this crazy code? When I got it, it was written in paragraph form, and no DBA *I * know writes SQL that complex in paragraph form, which leads me to believe that he used a GUI of some sort. Is this something Query Analyzer would do? Seems weird.
I'm not a total ignoramus...just a little out of my depth here. Ideas, anyone? Thanks!
Inger
For those of you who remember me from last week's post, I'm STILL trying to figure out what the heck my predecessor was thinking when he wrote this SQL query, among a variety of others:
Code:
CREATE VIEW dbo.vTime_ElapsedByTask
AS
SELECT
[BEGIN].[id], [BEGIN].user_id, [BEGIN].[Date], [BEGIN].Task_Code, [BEGIN].Project_task, [BEGIN].task_paid, [BEGIN].Project_Number, [BEGIN].LoginTime AS START, [STOP] = CASE WHEN MIN([END].LoginTime) IS NULL THEN getdate() ELSE MIN([END].LoginTime) END, [TimeOnTask] = CASE WHEN MIN([END].LoginTime) IS NULL THEN CONVERT(decimal(9, 2), DATEDIFF(s, [BEGIN].LoginTime, getdate())) / 60 / 60 ELSE CONVERT(decimal(9, 2), DATEDIFF(s, [BEGIN].LoginTime, MIN([END].LoginTime))) / 60 / 60 END
FROM dbo.vTime_Entries [END]
RIGHT OUTER JOIN dbo.vTime_Entries [BEGIN] ON [END].user_id = [BEGIN].user_id AND [END].LoginTime >= [BEGIN].LoginTime AND [BEGIN].[ID] <> [END].[ID]
GROUP BY [BEGIN].[id], [BEGIN].user_id, [BEGIN].[Date], [BEGIN].LoginTime, [BEGIN].Task_Code, [BEGIN].Project_task, [BEGIN].task_paid,
[BEGIN].Project_Number, [BEGIN].[Date]
Okay, A: BEGIN, END, START AND STOP are all reserved words. I'm unfamiliar with the practice of using them as...table names? BEGIN, incidentally, is not a table name listed in vTime_Entries, the view that this view queries.
and B: How is it that you can have 23 BEGINs and, like, 7 ENDs?
and C: Any idea what kind of WYSIWYG this guy used to get this crazy code? When I got it, it was written in paragraph form, and no DBA *I * know writes SQL that complex in paragraph form, which leads me to believe that he used a GUI of some sort. Is this something Query Analyzer would do? Seems weird.
I'm not a total ignoramus...just a little out of my depth here. Ideas, anyone? Thanks!
Inger