I just need it to pull the top 'last invoiced date' from the table not everything. any idea how to do that? Or could anyone point me in the right direction. I am a novice to sql queries. I'm using MS sql sever 2016.
Vendor_Number Vendor_Name VendorInvoiceDate DaysLastInvoiced
3568 a INDUSTRIES INC 2016-11-12 07:02:41.743 165
3568 a INDUSTRIES INC 2016-10-08 07:03:31.170 200
3568 a INDUSTRIES INC 2016-10-06 07:09:46.880 202
3568 a INDUSTRIES INC 2016-09-21 07:04:30.267 217
3568 a INDUSTRIES INC 2016-04-26 07:04:27.570 365
3215 o Outdoors, Inc. 2016-03-02 07:39:30.137 420
3215 o Outdoors, Inc. 2016-02-25 07:24:04.207 426
3215 o Outdoors, Inc. 2016-02-22 07:02:51.787 429
enter code here
Select distinct
REF02_VR as Vendor_Number
, N102_RI as Vendor_Name
, VendorInvoiceDate
, DATEDIFF(day,(select VendorInvoiceDate),Getdate()) AS DaysLastInvoiced
From
INSCIO_EDI810 a
WHERE
1 = 1
and
a.VendorInvoiceDate >= '2016-01-01 00:37:21.370'
order by
N102_ri, a.VendorInvoiceDate desc