SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kt
Yak Posting Veteran

75 Posts

Posted - 09/24/2013 :  15:51:03  Show Profile  Reply with Quote
The query inside in condion worked great. I now what to list those items from cib table but got error below:

Incorrect syntax near the keyword 'WITH'.
Msg 319, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
Msg 102, Level 15, State 1, Line 24
Incorrect syntax near ')'.

Can you pls help?

select t_item, t_kitm
from cib
where t_item
in (
WITH RecursiveBOM (LEVEL,t_mitm, t_sitm,t_kitm)
AS (SELECT 1,ROOT.t_mitm, ROOT.t_sitm, itm.t_kitm
FROM ttibom010110 ROOT with (nolock)
inner join ttcibd001110 itm with (nolock)
on ROOT.t_sitm= itm.t_item and itm.t_kitm =2
WHERE ltrim(ROOT.t_mitm) = '120400-221265TM'
Union All
SELECT PARENT.LEVEL+1, CHILD.t_mitm, CHILD.t_sitm,pr.t_kitm
FROM RecursiveBOM PARENT, ttibom010110 CHILD,ttcibd001110 pr
WHERE PARENT.t_sitm = CHILD.t_mitm and pr.t_item = CHILD.t_mitm
)
SELECT Rec.t_sitm
FROM RecursiveBOM as Rec
INNER JOIN tticpr007110 as icpr with (nolock)
ON Rec.t_sitm = icpr.t_item
where t_ecpr_1 ='0'
and Rec.t_kitm =2
OPTION (MAXRECURSION 10)

) as x
and t_kitm =1

Edited by - kt on 09/24/2013 15:53:34

bitsmed
Constraint Violating Yak Guru

277 Posts

Posted - 09/24/2013 :  16:15:55  Show Profile  Reply with Quote
Maybe this:

with recursivebom (level,t_mitm,t_sitm,t_kitm)
  as (select 1
            ,root.t_mitm
            ,root.t_sitm
            ,itm.t_kitm
        from ttibom010110 as root with (nolock)
             inner join ttcibd001110 as itm with (nolock)
                     on root.t_sitm=itm.t_item
                    and itm.t_kitm=2
       where ltrim(root.t_mitm)='120400-221265TM'
      union all
      select parent.level+1
            ,child.t_mitm
            ,child.t_sitm
            ,pr.t_kitm
        from recursivebom as parent
             inner join ttibom010110 as child
                     on child.t_mitm=parent.t_sitm
             inner join ttcibd001110 as pr
                     on pr.t_item=child.t_mitm
     )
select t_item
      ,t_kitm
  from cib
 where t_item in (select rec.t_sitm
                    from recursivebom as rec
                         inner join tticpr007110 as icpr with (nolock)
                                 on icpr.t_item=rec.t_sitm
                   where t_ecpr_1='0'
                     and rec.t_kitm=2
                   option (maxrecirsion 10)
                 )

Edited by - bitsmed on 09/24/2013 16:18:41
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000