改存储过程这种直接传递条件语句的处理需要动态sql语句来完成. 而用户定义函数是不支持的.
解决方案 »
- 请高手帮忙。
- 请教一SQL语句
- 筛选问题。
- 视图更新???????????????????????????
- 如何把聚集索引取消掉?
- 利用127.0.0.1不能连接数据库,但是用(local)就可以
- 关于SqlServer2000 服务管理器的问题
- 各位老大,在windows 2003上怎么装不上sql2000,我没有带补丁的sql2000能先安装上吗?
- 我在别人的一个视图代码中看到有一句cross join,请哪位说一下cross join的用法
- 一個sql的查詢
- 一个很奇怪的问题
- INTERBASE数据库中的数据表与SQL SERVER中的数据表对应,数据如何由INTERBASE导入SQL SERVER
(@s_p_no int = NULL,
@sql_where varchar = NULL)
returns @fn_getContent_Balance TABLE
(ID varchar(8000),
SupplyPlanNo int,
ItemCode varchar(20),
Vendor varchar(20)
)
as
BEGIN
/*Outer CURSOR*/
exec('DECLARE getItemBalance CURSOR SCROLL FOR
select ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from (
select min(ID) as ID,ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from Balance where SupplyPlanNo='+@s_p_no+'
group by ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
) a order by a.ID desc')
(@s_p_no int = NULL,
@sql_where varchar = NULL)
as
begin
set nocount on
declare @fn_getContent_Balance TABLE
(ID varchar(8000),
SupplyPlanNo int,
ItemCode varchar(20),
Vendor varchar(20)
)
/*Outer CURSOR*/
declare @@s_p_no varchar(10)
set @@s_p_no=@s_p_no
exec('
DECLARE getItemBalance CURSOR SCROLL global FOR
select ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from (
select min(ID) as ID,ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from Balance where SupplyPlanNo='+@@s_p_no+' and '+@sql_where+' -- *******
group by ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
) a order by a.ID desc')
end
CREATE proc xzc.fn_getContent_Balance
(@s_p_no int = NULL,
@sql_where varchar = NULL)
as
declare @fn_getContent_Balance TABLE
(ID varchar(8000),
SupplyPlanNo int,
ItemCode varchar(20),
Vendor varchar(20)
)
BEGIN
/*Outer CURSOR*/
exec('DECLARE getItemBalance CURSOR SCROLL FOR
select ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from (
select min(ID) as ID,ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
from Balance where SupplyPlanNo='+@s_p_no+'
group by ItemCode,ItemName,ItemSpec,UnitName,PlanPrice,Part,Vendor,VendorName
) a order by a.ID desc')
2.表定义记录最大长度为8060,你定义的超过了该值