Hi Hope someone can help.
My Query below semi works
FromDate formats the date like this '20131011' and To date does the same format minus 2 Months like this.
'20130711'
The nested query gets QTY Sold during FromDate & ToDate.
It returns 'NULL' when i run it as is in the below query.
If i replace the date query with '20130701' to '20131011' which is in the nested query, it returns the correct values.
What am i doing wrong ???
My Query below semi works
FromDate formats the date like this '20131011' and To date does the same format minus 2 Months like this.
'20130711'
The nested query gets QTY Sold during FromDate & ToDate.
It returns 'NULL' when i run it as is in the below query.
If i replace the date query with '20130701' to '20131011' which is in the nested query, it returns the correct values.
What am i doing wrong ???
Code:
DECLARE @FromDate as VARCHAR(8)
DECLARE @ToDate as VARCHAR(8)
set @FromDate = (select CONVERT(VARCHAR(8), GETDATE(), 112))
set @ToDate = (select CONVERT(VARCHAR(8), DATEADD(month, -3, GETDATE()), 112))
select
ITEM,
[DESC],
LOCATION,
QTYONHAND,
(
select SUM(OESHDT.QTYSOLD) from OESHDT
where OESHDT.ITEM = zzActiveItems.ITEM and
(OESHDT.TRANDATE >= (select CONVERT(VARCHAR(8), GETDATE(), 112)) and
OESHDT.TRANDATE <= (select CONVERT(VARCHAR(8), DATEADD(month, -3, GETDATE()), 112))) and
OESHDT.LOCATION = zzActiveItems.LOCATION
) as 'QTY_SOLD'
from zzActiveItems inner join ICITEM on ICITEM.ITEMNO = zzActiveItems.ITEM
