Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Help - Query not selecting specified Date Range

Hello all,

I was able to create a query to retrieve specific quotes for specific Item Groups.  I tried to narrow the search based on Document Date but for some reason it is not working.  Please let me know what I am doing wrong.

SELECT

  T3.[DocNum] AS 'Quote #'

  , T3.[DocStatus] AS 'Document Status'

  , T3.[CardCode] AS 'Customer Code'

  , T3.[CardName] AS 'Customer Name'

  , T3.[DocDate] AS 'Posting Date'

  , T3.[TaxDate] AS 'Document Date'

  , T3.[DocDueDate] AS 'Due Date'

  , T2.[ItemCode] AS 'Item No.'

  , T1.[ItemName] AS 'Item Description'

  , T1.[ItmsGrpCod] AS 'Item Group'

  , T0.[ItmsGrpNam] AS 'Group Name'

  , T4.[Price] AS 'Cost in PriceList'

  , T2.[GrossBuyPr] AS 'Cost from Quote'

FROM  [dbo].[OITB] T0

  INNER JOIN [dbo].[OITM] T1  ON  T1.[ItmsGrpCod] = T0.[ItmsGrpCod]  

  INNER  JOIN [dbo].[QUT1] T2  ON  T2.[ItemCode] = T1.[ItemCode]  AND  T2.[ItemCode] = T1.[ItemCode]  

  INNER  JOIN [dbo].[OQUT] T3  ON  T3.[DocEntry] = T2.[DocEntry]

  Left Outer Join ITM1 T4 on T4.PriceList = '23' and T1.ItemCode = T4.ItemCode  

WHERE

T0.[ItmsGrpNam] Like N'%TCN%'

OR T0.[ItmsGrpNam] Like N'%TFN%'

OR T0.[ItmsGrpNam] Like N'%TGN%'

OR T0.[ItmsGrpNam] Like N'%TN2%'

OR T0.[ItmsGrpNam] Like N'%TN3%'

OR T0.[ItmsGrpNam] Like N'%TN5%'

OR T0.[ItmsGrpNam] Like N'%TNA%'

and T3.[DocDate] >=[%0]

and  T3.[DocDate] <='[%1]'

Tags:
Former Member replied

Hi,

In your case I think you have to use brackets between OR and AND operator.Replace your Where condition like below one

WHERE

(T0.[ItmsGrpNam] Like N'%TCN%'

OR T0.[ItmsGrpNam] Like N'%TFN%'

OR T0.[ItmsGrpNam] Like N'%TGN%'

OR T0.[ItmsGrpNam] Like N'%TN2%'

OR T0.[ItmsGrpNam] Like N'%TN3%'

OR T0.[ItmsGrpNam] Like N'%TN5%'

OR T0.[ItmsGrpNam] Like N'%TNA%')

and T3.[DocDate] >=[%0]

and  T3.[DocDate] <='[%1]'

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question