newbhere wrote:Yes, it is what I am looking for. I am using only the SQL query.
How about if I want to generate sales report to include only for specific dates on all items/orders.
Thank you
Hi,
The New York solution would do the trick, but keep in mind that it will give you only the paid orders between the two dates. If you want to have all the orders you will have to use the CreatedOnUtc field instead of PaidDateUtc.
Select oi.OrderId, oi.ProductId, oi.AttributesXml from [Order] o
inner join [OrderItem] oi
on o.Id = oi.OrderId
where oi.AttributesXml != ''
and o.CreatedOnUtc between convert(datetime, '2016-01-01 00:00:00', 102) and convert(datetime, '2016-12-31 00:00:00', 102)
Note for my query: It will exclude the order products that do not have Attributes. If you want to include them, the query will look like this:
Select oi.OrderId, oi.ProductId, oi.AttributesXml from [Order] o
left join [OrderItem] oi
on o.Id = oi.OrderId
where o.CreatedOnUtc between convert(datetime, '2016-01-01 00:00:00', 102) and convert(datetime, '2016-12-31 00:00:00', 102)
About the order statuses, you can include them very easily. Just add the following expression to the where clause:
Select oi.OrderId, oi.ProductId, oi.AttributesXml from [Order] o
left join [OrderItem] oi
on o.Id = oi.OrderId
where
oi.AttributesXml != ''
and o.CreatedOnUtc between convert(datetime, '2016-01-01 00:00:00', 102) and convert(datetime, '2016-12-31 00:00:00', 102)
and o.OrderStatusId = 30
This will give you only the Complete orders.