Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Find Latest Date from Multiple Columns

$
0
0
I have ten user defined date fields, but for simplicity let's focus on three. These are only dates, not datetime. They're labeled L1, L2, and L3 and contain a date. They are manual entry so the date can be manually changed by the user. I need to find the latest date and the column header it belongs to.[code="sql"][/code]CREATE TABLE datetest (id varchar(8), L1 date, L2 date, L3 date)INSERT INTO datetest (id, L1, L2, L3) VALUES ('1005', '1-1-16', '1-17-16', '1-10-16')[code="sql"][/code]What I want to see is three columns: id, MAX date, Column it comes from. In the case above, I'd hope for:1005, 1-17-16, L2

Viewing all articles
Browse latest Browse all 3145

Trending Articles