I am trying to get only previous sixth month's data form the query.
i.e I have to group by only the previous sixth months.
Suppose current month is June then I only want January's data & also I don't want all the previous month other than January
Can anyone help me for this
SELECT
so_date
FROM
RS_Sells_Invoice_Info_Master SIIM
LEFT OUTER JOIN
RS_Sell_Order_Master AS SM ON SM.sell_order_no = SIIM.sell_order_no
LEFT OUTER JOIN
RS_Sell_Order_Mapping AS SOM ON SOM.sell_order_no = SIIM.sell_order_no AND SIIM.product_id = SOM.product_id
LEFT OUTER JOIN
RS_Inventory_Master AS IM ON IM.product_id = SIIM.product_id
where
so_date between CAST(DATEADD(month, DATEDIFF(month, 0, so_date)-5, 0)AS DATE) and CAST(DATEADD(month, DATEDIFF(month, 0, so_date)-4, 0)AS DATE)