Hi
I have below query . I want if For e.g Current month is say Feb 2025 then i want to add 3 colums Non 24,Dec 24 , Jan 25. I want to get Stock of items in these 3 months.
If current month is Jan 25 then Oct 24 , Nov 24 , Dec 24.
SELECT T0."WhsCode", T0."ItemCode",T0."OnHand"
FROM OITW T0 inner join OITM T1 on T0."ItemCode" = T1."ItemCode"
Muhammad Imran AnsariPosted Feb 15, 2025, 4:58 AM
Hello Ramco,
To achieve your requirement, you need to dynamically calculate the three months based on the current month and then retrieve the stock of items for those months. This can be done using SQL by calculating the months dynamically and joining the relevant tables.
Here’s how you can write the query:
Good Luck!
Emily FosterPosted Feb 15, 2025, 4:53 AM
Based on the information provided, the query is aimed at retrieving the stock of items for specific months as defined based on the current month. To cater to the requirement of fetching stock for the current month and the two months preceding it, adjustments need to be made to the query dynamically based on the current month.
Here's an approach you can consider for dynamically adding the three columns representing the months for which you need stock:
1. Determine the current month. For instance, if the current month is February 2025, the columns would be Non 24, Dec 24, and Jan 25.
2. Modify the SQL query to include the additional columns for the required months based on the current month.
Here's a conceptual example of how the SQL query might look based on the current month scenario you provided:
By incorporating this dynamic approach, you can adjust the query to fetch the stock information for the current month and the two months preceding it, ensuring flexibility and accuracy in retrieving the required data.