Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
dpustam
Starting Member
1 Post |
Posted - 2006-03-13 : 11:45:22
|
| I am try to do a query of dates.I have an access adp front end with sql2000 backendI am trying to query vacation dates.the start date month and day is based on month(hiredate) & day(hiredate)i need to find the number of days taken during a specific periodi have to use entering start date and end date and days.i am trying a query that returns sum of days before the end date changes.it works in sql analyzer but doesn't when i paste it in EMdoesn't want to save it. it says error by if..heres the code. SE EMPLOYEEIF { fn CURDATE() } > (SELECT distinct cast(Year(dbo.[Employment Information].[Hire Date]) as varchar(30)) + '-' + CAST(DATEPART([month], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(DATEPART([day], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30))FROM dbo.[Employment Information] INNER JOIN dbo.[Employee Vacation] ON dbo.[Employment Information].[Employee ID] = dbo.[Employee Vacation].[Employee ID])BEGINSELECT dbo.[Employee Vacation].[Employee ID], SUM(dbo.[Employee Vacation].[Number of Days]) AS [Days Taken]FROM dbo.[Employee Vacation] INNER JOIN dbo.[Employment Information] ON dbo.[Employee Vacation].[Employee ID] = dbo.[Employment Information].[Employee ID]WHERE (dbo.[Employee Vacation].[Start Date] BETWEEN CAST(DATEPART([month], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(DATEPART([day], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(YEAR({ fn CURDATE() }) AS VARCHAR(30)) AND CAST(DATEPART([month], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(DATEPART([day], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(YEAR({ fn CURDATE() })+ 1 AS VARCHAR(30)))GROUP BY dbo.[Employee Vacation].[Employee ID]ENDELSEBEGINSELECT dbo.[Employee Vacation].[Employee ID], SUM(dbo.[Employee Vacation].[Number of Days]) AS [Days Taken]FROM dbo.[Employee Vacation] INNER JOIN dbo.[Employment Information] ON dbo.[Employee Vacation].[Employee ID] = dbo.[Employment Information].[Employee ID]WHERE (dbo.[Employee Vacation].[Start Date] BETWEEN CAST(DATEPART([month], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(DATEPART([day], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(YEAR({ fn CURDATE() }) - 1 AS VARCHAR(30)) AND CAST(DATEPART([month], dbo.[Employment Information].[Hire Date]) AS VARCHAR(30)) + '-' + CAST(DATEPART([day], dbo.[Employment Information].[Hire Date])- 1 AS VARCHAR(30)) + '-' + CAST(YEAR({ fn CURDATE() }) AS VARCHAR(30)))GROUP BY dbo.[Employee Vacation].[Employee ID]END |
|
|
AndrewMurphy
Master Smack Fu Yak Hacker
2916 Posts |
Posted - 2006-03-13 : 12:07:20
|
| Access SQL is not equal to T-SQL and does not always run 'out-of-the-box-without-change'. You need to convert some of your code to comply with T-SQL systax rules. Read up on the differences between the 2 versions of the language and search here for some examples. |
 |
|
|
|
|
|
|
|