hie all,
my query is this
select * from [order] where createdon<getdate()-7
and orderid between
(select top 1 orderid from [order] where createdon<getdate()-7 order by orderid) as oId
and oId+100 order by orderid
It is giving error. please tell me where is it going wrong
my intention is to get 100 orders from order table which are older than 7 days. and please dont suggest fetching it using row_number
Thanks
You can’t alias expressions in the
WHEREclause. But since your subquery returns just one row, you could cross join it to the[order]table and filter on the returned toporderidvalue like this: