@zzxbg bit = 1
AS
BEGIN
SET NOCOUNT ON;
WITH tb(Invoice_No, chxi, ForAccountof, NotifyParty, Consignee, gs) AS
(
SELECT a.Invoice_No, a.chxi, c.ForAccountof, c.NotifyParty, c.Consignee, c.gs
from tb1
)
if zzxbg = 1
begin
....
endEND以上语句出错"关键字 'if' 附近有语法错误。"请问with 后只能跟select关键字, 不能用if 语句是吗?
AS
BEGIN
SET NOCOUNT ON;
if zzxbg != 1
begin
WITH tb(Invoice_No, chxi, ForAccountof, NotifyParty, Consignee, gs) AS
(
SELECT a.Invoice_No, a.chxi, c.ForAccountof, c.NotifyParty, c.Consignee, c.gs
from tb1
)
end
if zzxbg = 1
begin
endEND
这样看可以不?
AS
BEGIN
SET NOCOUNT ON;
WITH tb(Invoice_No, chxi, ForAccountof, NotifyParty, Consignee, gs) AS
(
SELECT a.Invoice_No, a.chxi, c.ForAccountof, c.NotifyParty, c.Consignee, c.gs
from tb1
)
--可以这样
select case @zzxbg when 1 then '' else '' endEND
;with m as (select 1 as col)
insert into @t select * from m