View Issue Details

IDProjectCategoryView StatusLast Update
0000971Database ComparerGeneralpublic2019-04-18 12:44
Reportershirokov Assigned Tobarry  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Fixed in Version7.0.0.1680 
Summary0000971: SQL Compare error with "cross apply values" statement
DescriptionIt seems, the current version of the comparer doesn't support the CROSS APPLY statement for the SELECT command.

The script is attached.
TagsNo tags attached.

Activities

shirokov

2016-10-03 13:29

administrator  

cross apply values.txt (2,395 bytes)   
CREATE FUNCTION [dbo].[APPOINTMENT_GAPS_SINGLE] 
(@DATES DATES,
 @LICENSE LICENSE)
 RETURNS TABLE
 AS
RETURN

WITH Gaps AS (
        SELECT ID_EMPLOYEE_GUID, ts, [Type]
            ,e=CASE [Type] WHEN 1 THEN NULL ELSE ROW_NUMBER() OVER (PARTITION BY ID_EMPLOYEE_GUID, [Type] ORDER BY TIME_UNTILL) END
            ,s=CASE [Type] WHEN -1 THEN NULL ELSE ROW_NUMBER() OVER (PARTITION BY ID_EMPLOYEE_GUID, [Type] ORDER BY TIME_FROM) END
        FROM APPOINTMENT_OCCUPIED(@DATES, @LICENSE)
        CROSS APPLY (
            VALUES (1, TIME_FROM), (-1, TIME_UNTILL)) a([Type], ts)
        ),
    C2 AS (
        SELECT Gaps.
            ,se=ROW_NUMBER() OVER (PARTITION BY ID_EMPLOYEE_GUID ORDER BY ts, [Type] DESC)
        FROM Gaps),
    C3 AS (
        SELECT ID_EMPLOYEE_GUID, ts
            ,grpnm=FLOOR((ROW_NUMBER() OVER (PARTITION BY ID_EMPLOYEE_GUID ORDER BY ts)-1)  2 + 1)
        FROM C2
        WHERE COALESCE(s-(se-s)-1, (se-e)-e) = 0),
    MinMax AS (
        SELECT ID_EMPLOYEE_GUID, TIME_FROM=MIN(ts), TIME_UNTILL=MAX(ts)
        FROM C3
        GROUP BY ID_EMPLOYEE_GUID, grpnm)

-- Convert the Islands from MinMax into gaps (method by Dwain.C)
-- httpswww.simple-talk.comsqlt-sql-programmingthe-sql-of-gaps-and-islands-in-sequences
SELECT ID_EMPLOYEE_GUID, TIME_FROM=MIN([date]), TIME_UNTILL=MAX([date])
FROM (

		SELECT ID_EMPLOYEE_GUID, [date], rn=ROW_NUMBER() OVER (PARTITION BY ID_EMPLOYEE_GUID ORDER BY [date])2

		FROM (
			-- Normally this would be a CROSS APPLY VALUES but this works in SQL 2005
			SELECT ID_EMPLOYEE_GUID, [date]=TIME_FROM
			FROM MinMax
			UNION ALL
			SELECT ID_EMPLOYEE_GUID, [date]=TIME_UNTILL
			FROM MinMax
			 ) a
	 ) a
--cross apply (values(StartDate), (EndDate)) b ([date])) b
--inner join vEMPLOYEE as e on e.ID_GUID = a.ID_EMPLOYEE_GUID
--where e.IND_WEBSITE = 'Y'
--where
-- id_employee_guid = '0B13951D-5E31-42FA-952A-E2A56F5C8001'

--and
 --[date] between '2182016' and '2292016'

GROUP BY ID_EMPLOYEE_GUID, rn
HAVING COUNT() = 2
and DATEDIFF(mi, MIN([date]), MAX([date])) = 5
and DATEPART(weekday, MIN([date])) = DATEPART(weekday, MAX([date]))
and DATEDIFF(hh, MIN([date]), MAX([date])) = 23


--   and DATEDIFF(hh, MIN([date]), MAX([date])) = 14
--   and DATEPART(weekday, MIN([date])) = DATEPART(weekday, MAX([date]))
--   and DATEDIFF(mi, MIN([date]), MAX([date])) = 5

--;
cross apply values.txt (2,395 bytes)   

Issue History

Date Modified Username Field Change
2016-10-03 13:29 shirokov New Issue
2016-10-03 13:29 shirokov File Added: cross apply values.txt
2019-04-18 12:26 barry Assigned To => barry
2019-04-18 12:26 barry Status new => acknowledged
2019-04-18 12:44 barry Status acknowledged => closed
2019-04-18 12:44 barry Resolution open => fixed
2019-04-18 12:44 barry Fixed in Version => 7.0.0.1680