Skip to Content
author's profile photo Former Member
Former Member

query is not filtering the data as per the parameters

Dear Experts, I am using the following the query get the required data. but SAP query generator is not filtering the data as per the parameters provided.

declare @FromDate Date

declare @ToDate Date

set @FromDate= (select Distinct(T0.[createdate]) from oitm T0 where T0.[CreateDate] =[%1])

set @ToDate =(select Distinct(T0.[createdate]) from oitm T0 where T0.[CreateDate] =[%2])

-- system is not filtering the required data result, based on underneath query with reference to the above variable get using [%1], [%2]and stored in @FromData and @ToData

SELECT T0.[ItemCode], T0.[ItemName],T1.[ItmsGrpNam],

(CASE WHEN T0.[QryGroup1]='Y' THEN 'CS-RAW MATERIAL'

WHEN T0.[QryGroup2]='Y' THEN 'STML-RAW MATERIAL'

WHEN T0.[QryGroup2]='Y' THEN 'CS-FINISHED GOODS'

WHEN T0.[QryGroup2]='Y' THEN 'STML-FINISHED GOODS'

WHEN T0.[QryGroup2]='Y' THEN 'CS-STORE AND SPARE'

WHEN T0.[QryGroup2]='Y' THEN 'STML-STORE AND SPARE'

ELSE ''

END) as Itms_Property

,T0.CreateDate,@FromDate as FromDate,@ToDate as ToDate,T0.OnHand,

isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<@FromDate),'0.00')+

isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<@FromDate),'0.00')-

isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<@FromDate),'0.00')-

isnull ((select sum(DLN1.Quantity) from DLN1 where DLN1.ItemCode =T0.ItemCode and DLN1.docdate<@FromDate),'0.00')

as Opening_QTY,

(select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate>=@FromDate and IGN1.docdate<=@ToDate) as GoodReceipt_QTY,

(select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate>=@FromDate and PDN1.docdate<=@ToDate) as GRN_QTY,

(select sum(WTR1.Quantity) from WTR1 where WTR1.ItemCode =T0.ItemCode and WTR1.docdate>=@FromDate and WTR1.docdate<=@ToDate)as IM_QTY,

(select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate>=@FromDate and IGE1.docdate<=@ToDate)as ISSUE_QTY,

isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<=@ToDate),'0.00')+

isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<=@ToDate),'0.00')-

isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<=@ToDate),'0.00')

as Closing_QTY

FROM OITM T0 INNER JOIN OITB T1 ON T0.[ItmsGrpCod] = T1.[ItmsGrpCod]

regards

Awais

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Posted on Dec 16, 2014 at 08:02 AM

    Hi,

    Try:

    Declare @fromdate as Datetime
    Declare @todate as datetime
    set @FromDate= (select Distinct(T0.[createdate]) from oitm T0 where T0.[CreateDate] =[%1])
    set @ToDate =(select Distinct(T0.[createdate]) from oitm T0 where T0.[CreateDate] =[%2])
    SELECT T0.[ItemCode], T0.[ItemName],T1.[ItmsGrpNam],
    (CASE WHEN T0.[QryGroup1]='Y' THEN 'CS-RAW MATERIAL'
    WHEN T0.[QryGroup2]='Y' THEN 'STML-RAW MATERIAL'

    WHEN T0.[QryGroup2]='Y' THEN 'CS-FINISHED GOODS'

    WHEN T0.[QryGroup2]='Y' THEN 'STML-FINISHED GOODS'

    WHEN T0.[QryGroup2]='Y' THEN 'CS-STORE AND SPARE'

    WHEN T0.[QryGroup2]='Y' THEN 'STML-STORE AND SPARE'

    ELSE ''

    END) as Itms_Property

    ,T0.CreateDate,@FromDate as FromDate,@ToDate as ToDate,T0.OnHand,

    isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<@FromDate),'0.00')+

    isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<@FromDate),'0.00')-

    isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<@FromDate),'0.00')-

    isnull ((select sum(DLN1.Quantity) from DLN1 where DLN1.ItemCode =T0.ItemCode and DLN1.docdate<@FromDate),'0.00')
    as Opening_QTY,

    (select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate>=@FromDate and IGN1.docdate<=@ToDate) as GoodReceipt_QTY,

    (select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate>=@FromDate and PDN1.docdate<=@ToDate) as GRN_QTY,

    (select sum(WTR1.Quantity) from WTR1 where WTR1.ItemCode =T0.ItemCode and WTR1.docdate>=@FromDate and WTR1.docdate<=@ToDate)as IM_QTY,

    (select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate>=@FromDate and IGE1.docdate<=@ToDate)as ISSUE_QTY,

    isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<=@ToDate),'0.00')+

    isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<=@ToDate),'0.00')-

    isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<=@ToDate),'0.00')

    as Closing_QTY

    FROM OITM T0 INNER JOIN OITB T1 ON T0.[ItmsGrpCod] = T1.[ItmsGrpCod]

    Thanks & Regards,

    Nagarajan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 16, 2014 at 10:12 AM

    Hi Awais,

    Try this.

    declare @FromDate Date

    declare @ToDate Date

    set @FromDate = (select max(T0.[createdate]) from oitm T0 where T0.[CreateDate] <= [%1])

    set @ToDate =(select min(T0.[createdate]) from oitm T0 where T0.[CreateDate] >=[%2])

    SELECT T0.[ItemCode], T0.[ItemName],T1.[ItmsGrpNam],

    (CASE WHEN T0.[QryGroup1]='Y' THEN 'CS-RAW MATERIAL'

    WHEN T0.[QryGroup2]='Y' THEN 'STML-RAW MATERIAL'

    WHEN T0.[QryGroup2]='Y' THEN 'CS-FINISHED GOODS'

    WHEN T0.[QryGroup2]='Y' THEN 'STML-FINISHED GOODS'

    WHEN T0.[QryGroup2]='Y' THEN 'CS-STORE AND SPARE'

    WHEN T0.[QryGroup2]='Y' THEN 'STML-STORE AND SPARE'

    ELSE ''

    END) as Itms_Property

    ,T0.CreateDate,@FromDate as FromDate,@ToDate as ToDate,T0.OnHand,

    isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<@FromDate),'0.00')+

    isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<@FromDate),'0.00')-

    isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<@FromDate),'0.00')-

    isnull ((select sum(DLN1.Quantity) from DLN1 where DLN1.ItemCode =T0.ItemCode and DLN1.docdate<@FromDate),'0.00')

    as Opening_QTY,

    (select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate>=@FromDate and IGN1.docdate<=@ToDate) as GoodReceipt_QTY,

    (select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate>=@FromDate and PDN1.docdate<=@ToDate) as GRN_QTY,

    (select sum(WTR1.Quantity) from WTR1 where WTR1.ItemCode =T0.ItemCode and WTR1.docdate>=@FromDate and WTR1.docdate<=@ToDate)as IM_QTY,

    (select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate>=@FromDate and IGE1.docdate<=@ToDate)as ISSUE_QTY,

    isnull ((select sum(IGN1.Quantity) from IGN1 where IGN1.ItemCode =T0.ItemCode and IGN1.docdate<=@ToDate),'0.00')+

    isnull ((select sum(pdn1.Quantity) from pdn1 where pdn1.ItemCode =T0.ItemCode and PDN1.docdate<=@ToDate),'0.00')-

    isnull ((select sum(IGE1.Quantity) from IGE1 where IGE1.ItemCode =T0.ItemCode and IGE1.docdate<=@ToDate),'0.00')

    as Closing_QTY

    FROM OITM T0 INNER JOIN OITB T1 ON T0.[ItmsGrpCod] = T1.[ItmsGrpCod]

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 16, 2014 at 02:25 PM

    Hi Awais,

    try this


    set @fromdate=[%0]

    set @todate=[%1]


    while executing query ,manually type your date


    with regards,


    Bharathi raja

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.