Your technology certification is waiting. Enroll in Cloud Class ®
Declare @temp TABLE (rid int IDENTITY(1,1) PRIMARY KEY, data int)
INSERT INTO @temp (data)
SELECT fieldname2 FROM Table2
ORDER BY fieldname2
SELECT T.fieldname1, A.rid, A.Data, B.Data
INNER JOIN @temp B ON A.rid + 1 = B.rid
INNER JOIN Table1 T ON T.fieldname1 >= A.Data AND T.fieldname1 < B.Data
Open in new window
SELECT t1.*, range = (SELECT MAX(t2.fieldname) FROM tableB t2 WHERE t1.fieldname>=t2.fieldname)
FROM tableA t1
SELECT t1.*, t2.*
FROM tableA t1 OUTER APPLY
(SELECT TOP 1 *
ORDER BY fieldname DESC
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.