【发布时间】:2019-09-07 05:43:02
【问题描述】:
我在where 子句中添加了表函数。
select cmp_id, acno_code, sl_type, sl_code, 0 op_Dr, 0 op_cr, 0 tr_Dr, sum(amount) tr_Cr
from vf_finance
where cmp_id =@cmp_id1
and unitcode in (select * from UTILfn_Split( @unit_code,',') )
and stat_code in ('AT','PR' )
--and pc_code in (select * from UTILfn_Split( @sba,',') )
AND DOC_dT >=convert(datetime,@from_date,103) and doc_Dt <= convert(datetime,@to_date,103)
and amount < 0
GROUP BY cmp_id, acno_code, sl_type, sl_code
) as gl
inner join ps_Accmas acc on acc.cmp_id = gl.cmp_id and acc.acno_Code = gl.acno_code
inner join ps_owner o on gl.cmp_id = o.cmp_id
left outer join view_sl_code sl on gl.cmp_id = sl.cmp_id and gl.sl_type = sl.sl_type and gl.sl_Code = sl.sl_Code
inner join ps_slType slt on gl.cmp_id = slt.cmp_id and gl.sl_Type = slt.sl_type
where sl.sl_type in (select * from UTILfn_Split( @sl_type,',') )
and acc.acno_code in(select * from UTILfn_Split( @facno_code,',') )
group by gl.cmp_id, gl.acno_code,gl.sl_code,gl.sl_type,slt.sl_DEsc,acc.acno_DEsc, sl.sl_DEsc, o.owner_name
order by gl.cmp_id, gl.acno_code,gl.sl_code,gl.sl_type
谁能建议我如何避免where 子句中的功能?
【问题讨论】:
-
你试过
inner join UTILfn_Split(@sl_type, ',') sl2 on sl2.Value=sl.sl_type吗?此外,SQL Server 2016 及更高版本具有内置STRING_SPLIT() function。 -
再次检查您的查询,
) as gl似乎没有起始括号....检查并先更正
标签: sql-server database sql-server-2008 stored-functions