当前位置: 代码迷 >> Sql Server >> 必须声明标量变量 "@单位"和 "@财务分区"
  详细解决方案

必须声明标量变量 "@单位"和 "@财务分区"

热度:510   发布时间:2016-04-24 09:17:32.0
必须声明标量变量 "@机构"和 "@财务分区"
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参数。
  相关解决方案