sql server - T-SQL extract image from Max(Date) -
i have pictures in database need extract. image column of type varbinary(max)
.
i tried several examples using either join or subquery no avail. query developed work if wasn't image. using distinct
, max(date)
still can't eliminnate older image. many ids have multiple pictures. using max(date)
extract recent date, adding in picture eliminates filtering.
the query looks this:
select distinct id, image, datemodified, getdate() images type = 'b' id image datemod type 1 0x789 01-02-2014 b 1 0x791 11-12-2015 b <-- tgt record 2 0x675 12-01-2015 5 0x324 06-26-2015 b <-- tgt record
if use max(datemodified)
, forces group by
, still doesn't eliminate older images. need newest type 'b' image each id. working on sql server 2012.
what need output image, id, datemodified, todaysdate (getdate)
pretty sure want this.
with sortedresults ( select id , image , datemod , type , row_number() on (partition id order datemod desc) rownum images type = 'b' ) select id , image , datemod , getdate() sortedresults rownum = 1
Comments
Post a Comment