Skip to Content
0
Dec 18, 2013 at 01:43 PM

Query Manager

52 Views

Hi dear experts..

I need a little help with a query..

I wrote this query:

DECLARE @codice nvarchar(25), @datefrom datetime(6), @dateto datetime
select @codice = a.itemcode from oitm a where a.itemcode = '[%0]'
select @datefrom = [%1]
select @dateto = [%2]

;
With BOM (Parent,Child,qta,Level) As  
    (  
    Select
        T0.Father Parent,T0.Code Child,T0.quantity, 0 Level  
    From
        ITT1 T0 
        inner join oitm B on T0.father = B.itemcode 
        inner join oitm C on T0.code = C.itemcode
    where
        t0.code = @codice
    Union All
    Select
        T1.Father,T1.Code,T1.quantity,Level+1  
    From
        Itt1 T1 Inner join BOM T2 on T1.code=T2.parent
    )
    Select T4.* , t5.lastpurdat, t5.validfor
    from BOM T4 inner join oitm T5 on t4.parent = t5.itemcode
    where t5.lastpurdat between  @datefrom and @dateto
    and t5.validfor = 'y'
    order by t4.parent
    
    Option (MAXRECURSION 99)

Well... The variable @codice work fine.. I've problem with the variables @datefrom and @dateto.

If i insert 010113 (01/01/2013) in @datefrom and 100113 (10/01/2013) in @dateto the result is 10.09.27 for @datefrom and 06.02.74 for @dateto.

How can i set the query to work in correct way?

Sorry for my english and thanks in advance