select a.c_rec_store_id,c.c_name,a.c_provider,d.c_name as name, a.c_adno,
a.c_rec_type,case when b.c_tax_rate=13 or b.c_tax_rate=14.94 or b.c_tax_rate=14.93 then 13.00 else 17.00 end as c_tax_rate_disp,round(sum(b.c_pt_pay*b.c_rec_n),2) as c_a_in,sum(b.c_rec_n) as c_n_rec into #s
from tb_o_i a(nolock) inner join tb_o_ig b(nolock) on a.c_id=b.c_id
left join tb_store c(nolock) on a.c_rec_store_id=c.c_id
left join tb_partner d(nolock) on a.c_provider=d.c_no
where ( @机构='' or a.c_rec_store_id like @机构+'%' )
and ( @供应商编码='' or a.c_provider = @供应商编码 )
and ( @部门='' or a.c_adno like @部门+'%' )
AND datediff(day,a.c_rec_au_dt,@开始日期__datetime)<=0
AND datediff(day,a.c_rec_au_dt,@结束日期__datetime)>=0
and (exists(select * from tb_store(nolock) where c_settle_region=@财务分区 and tb_store.c_id=a.c_rec_store_id)
or @财务分区='' )
group by a.c_rec_store_id,a.c_provider, a.c_adno,
a.c_rec_type,case when b.c_tax_rate=13 or b.c_tax_rate=14.94 or b.c_tax_rate=14.93 then 13.00 else 17.00 end,c.c_name,d.c_name
------解决思路----------------------
如果是在查询分析器中执行,前面需要定义所有@开头的变量并赋值。
如果是在程序中通过SqlCommand调用,那么要加对应的SqlParameter参数。