CREATE
TABLE
[dbo].[test_assign] (
[
name
] [
varchar
](25)
NULL
,[datestart] [
date
]
,[dateEnd] [
,[assign_id] [
int
] IDENTITY(1, 1)
NOT
,
CONSTRAINT
[PK_test_assign]
PRIMARY
KEY
CLUSTERED ([assign_id]
ASC
)
WITH
(
PAD_INDEX =
OFF
,STATISTICS_NORECOMPUTE =
,IGNORE_DUP_KEY =
,ALLOW_ROW_LOCKS =
ON
,ALLOW_PAGE_LOCKS =
[dbo].[test_measure] (
,[measurementDate] [
,[measure_id] [
[PK_test_measure]
CLUSTERED ([measure_id]
INSERT
INTO
Test_Measure (
NAME
,Measurementdate
SELECT
'Adam'
'1/1/2001'
'2/2/2002'
Test_assign (
,DateStart
,DateEnd
'1/15/2001'
'12/31/2001'
'2/15/2002'
'12/31/2002'
'3/15/2003'
'12/31/2003'
-- Solution starts now
TA.*
,M.MeasurementDate
FROM
Test_Assign TA
OUTER
APPLY (
TOP
(1) *
Test_Measure TM
WHERE
TM.
= TA.
AND
TM.MeasurementDate <= TA.Datestart
ORDER
BY
TM.MeasurementDate
DESC
) M
Naomi N edited Revision 6. Comment: Added See Also
Naomi N edited Revision 5. Comment: Changed to past tense
Naomi N edited Revision 4. Comment: Minor edit
Naomi N edited Revision 1. Comment: Added last line about contest
Naomi N edited Original. Comment: More content