Hi Guys,
Happy New Year. I am a beginner to SQL. I am having some challenging on how to indentify current, previous and next customer for a customer renters table. Please the table below. Any help is appreciated.
CREATE TABLE #temp([rentid] char NOT NULL
,fullName varchar(255)
,rentref varchar(30)
,memberid varchar(30)
,rentstartdate DATETIME
,rentenddate DATETIME
,unrentvoiddate DATETIME
)
INSERT INTO #temp(rentid, rentref, fullName,memberid, rentstartdate,rentenddate,unrentvoiddate ) SELECT '100020003','Ms XXXXXXXXX', '100020003/003', '1016819767', '2014-09-15 00:00:00','2015-11-15 00:00:00','2015-11-16 00:00:00.000'
INSERT INTO #temp(rentid, rentref,fullName, memberid, rentstartdate,rentenddate,unrentvoiddate ) SELECT '100020003','Mr YYYYYYYYY', '100020003/004', '1021242816', '2015-12-21 00:00:00','2017-05-28 00:00:00','2017-05-29 00:00:00.000'
INSERT INTO #temp(rentid, rentref,fullName, memberid, rentstartdate,rentenddate,unrentvoiddate ) SELECT '100020003','Dr TTTTTTTTT', '100020003/005', '1021475396', '2017-06-19 00:00:00','2017-07-23 00:00:00','2017-07-24 00:00:00.000'
Select * from #temp
--Problem:
--The table contains list of car renters history - current and previous owners.
-- In addition to the lists, I want to add extra 5 columns to identify the previous, current and next ---member customers and Initial_unrentvoiddate and Current_unrentvoiddate
CREATE TABLE #temp([rentid] char NOT NULL
,Customer varchar(255)
,rentref varchar(30)
,memberid varchar(30)
,rentstartdate DATETIME
,rentenddate DATETIME
,unrentvoiddate DATETIME
,CurrentCustomer varchar(255)
,NextCustomer varchar(255)
,PreviousCustomer varchar(255)
,Initial_unrentvoiddate DATETIME
,Current_unrentvoiddate DATETIME
)
Thanking you in advance.
Ravin