SQL编程问题

时间:2011-01-17 15:25:30

标签: sql sql-server

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

我一直收到错误,说关键字'with'附近的语法不正确。有什么想法吗?

1 个答案:

答案 0 :(得分:5)

在'with'之前放置一个半冒号 - 它必须是语句中的第一个元素