I'm having a problem when trying to insert parameters into a derived table that is part of my table adapter fill query in a vb.net application.
I'm getting the "Conversion failed when converting date and/or time from character string" when I try to use the query in vb.net through the preview window of the Dataset Designer or using the datatableadapter.fill method in my application.
SELECT Date, SUM(RegHours) AS RegTotal, SUM(OTHours) AS OTTotal, SUM(VacHours) AS VacTotal, SUM(SickHours) AS SickTotal
FROM (SELECT EmployeeId, Date, RegHours, OTHours, (CASE WHEN TaskId=4 THEN RegHours ELSE NULL END) AS VacHours, (CASE WHEN TaskId=5 THEN RegHours ELSE NULL END) AS SickHours FROM TimeEntry
WHERE (EmployeeId=@EmployeeId) AND (Date>=@StartDate)) AS SubTable
GROUP BY Date
The query works perfectly when I have just the @EmployeeId parameter so the issue is with the date conversion.
The query also works fine if I do just the derived table portion:
SELECT EmployeeId, Date, RegHours, OTHours, (CASE WHEN TaskId=4 THEN RegHours ELSE NULL END) AS VacHours, (CASE WHEN TaskId=5 THEN RegHours ELSE NULL END) AS SickHours
FROM TimeEntry
WHERE (EmployeeId=@EmployeeId) AND (Date>=@StartDate)
Any help would be greatly appreciated!