0
DECLARE @Item as char(32)
declare @result varchar(max)
SET @Item = 'FL1823'

with Bom
 (
 StartItem, MasterItem, Position, SubItem, SubItemDescription, EffectDate, ExpiryDate, NetQuantity, UnitOfMeasure, BomLevel, Dots, Sort) as
(
select t_mitm as StartItem, t_mitm, t_pono, t_sitm, t_dsca, t_indt, t_exdt, t_qana, t_cuni, 0 as BomLevel, CONVERT(varchar(255),'.'), CONVERT(varchar(255),RTrim(t_mitm) + ' ' +RTrim(t_sitm))

from ttibom010101 INNER JOIN ttiitm001101 on t_sitm = t_item where t_mitm =@Item

UNION ALL

SELECT     StartItem, t_mitm, t_pono, t_sitm, t_dsca, t_indt, t_exdt, NetQuantity * t_qana, t_cuni,BomLevel + 1, CONVERT(varchar(255),'.' + Dots), CONVERT(varchar(255),RTrim(Sort)+ ' ' + RTrim(t_sitm))
FROM         (ttibom010101 INNER JOIN ttiitm001101 on t_sitm = t_item) INNER JOIN
                     Bom ON t_mitm = SubItem where t_exdt= '1753-01-01'
)
Select * from Bom order by Sort

I keep getting an error saying incorrect syntax near the keyword 'with'. Any thoughts on that?

1
  • WITH was added in SQL2005. What version of the database engine are you using? If you're not sure: Select @@Version Commented Jan 17, 2011 at 15:30

1 Answer 1

5

put a semi colon before the 'with' - it has to be the first element in a statement

Sign up to request clarification or add additional context in comments.

2 Comments

@gabrielVA Also, you are missing the word AS. It should be like this: SET @ITEM = 'FL1823'; WITH Bom AS (
@Lamak: there is an AS at the end of the line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.