asked on
WITH cte_MyCTE AS (
SELECT
tbl1.[MyPID],
tbl1.[MyDate],
tbl2.[MyNumber],
tbl2.[MyOtherNumber],
DENSE_RANK() OVER(ORDER BY tbl1.[MyPID], tbl1.[MyNumber], DATEADD(HOUR, (DATEDIFF(HOUR, '1900-01-01 00:00:00.000', tbl1.[MyDate]/3)*3, '1900-01-01 00:00:00.000')) AS [MyGrpID]
FROM Table1 AS tbl1
LEFT JOIN Table2 AS tbl2
)
INSERT INTO Table3
SELECT DISTINCT
[MyGrpID],
[MyPID],
[MyNumber],
[MyOtherNumber]
FROM cte_MyCTE
ASKER
SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.
TRUSTED BY
ASKER
Not sure why it worked but it definitely did!
Can you point me to something that explains why? Either way - NICE JOB!