cancel
Showing results for 
Search instead for 
Did you mean: 

Help - Query not selecting specified Date Range

keith_hitchner
Participant
0 Kudos

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]'

Accepted Solutions (1)

Accepted Solutions (1)

keith_hitchner
Participant
0 Kudos

I should have clarified - the query retrieves all of the quotes since we started using the system for the specific item groups.  I want to narrow the selection to a specific date range (normally a month or quarter).

Former Member
0 Kudos

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]'

keith_hitchner
Participant
0 Kudos

Thank you - that worked perfect.

Answers (0)