Take a simple table like below:
Column Headings: || Agent's Name || Time Logged In || Center ||
Row 1: Andrew || 12:30 PM || Home Base
Row 2: Jeff || 7:00 AM || Virtual Base
Row 3: Ryan || 6:30 PM || Test Base
Now lets say that a single cell is deleted so the table now looks like this:
Column Headings: || Agent's Name || Time Logged In || Center ||
Row 1: Andrew || 12:30 PM ||
Row 2: Jeff || 7:00 AM || Virtual Base
Row 3: Ryan || 6:30 PM || Test Base
Notice that “Home Base” is missing. Now in excel you can delete the cell and shift the rest so the finished product looks like below:
Column Headings: || Agent's Name || Time Logged In || Center ||
Row 1: Andrew || 12:30 PM || Virtual Base
Row 2: Jeff || 7:00 AM || Test Base
Row 3: Ryan || 6:30 PM ||
And you can see we are left with a blank cell last row.
How do I code this procedure of shifting the cells up in SQL?
I’ve been struggling on this problem for weeks! Thank you!
One of many options is to use an
outer applyto fetch the Center from the next row:You do have to specify an ordering (the example orders on name.)