请问如何在存储过程中加函数的问题!
现在,我有一个函数,返回是一些sql 的条件
譬如,函数中返回name like '%我%' or name like '%他%'
在存储过程中要把此返回的字符串作为条件
例如:
select * from student where "函数中返回的字符串" group by id
我在存储过程中直接引用函数提示有语法错误
请问如何实现?
问题点数:0、回复次数:7Top
1 楼winternet(冬天)回复于 2005-05-03 19:28:00 得分 0
create proc Test
as
declare @Condition nvarchar(200),@s nvarchar(4000)
select @Condition=dbo.函數名
select @s=''
select @s=@s+'select * from student where '+@Condition +' group by id'
exec(@s)
go
Top
2 楼orcale()回复于 2005-05-03 20:30:50 得分 0
寫動態sql
exec('select '+...)Top
3 楼kainzgy(ICE)回复于 2005-05-07 11:19:45 得分 0
RE: winternet(冬天)
我按你的方法可以加条件,但是当我把这些按条件检索出来的记录插入到一个存储过程中定义的一个表中是,老是提示改表没有定义.我的部分代码如下:
declare @indextable table(id int identity(1,1),nid int)
declare @Condition nvarchar(200),@s nvarchar(4000)
select @Condition=dbo.函數名
select @s=''
select @s=@s+' insert into '+@indextable(nid)+'select id from student where '+@Condition +' group by id'
提示@indextable没有定义,请问应该怎么写??
Top
4 楼paoluo(一天到晚游泳的鱼)回复于 2005-05-07 11:45:20 得分 0
试试这样
declare @Condition nvarchar(200),@s nvarchar(4000)
select @Condition=dbo.函數名
select @s='declare @indextable table(id int identity(1,1),nid int)'
select @s=@s+' insert into '+@indextable(nid)+'select id from student where '+@Condition +' group by id'
--select @s=@s+' Select * from @indextable'
EXEC(@s)Top
5 楼heguosheng(何国胜)回复于 2005-05-07 17:00:18 得分 0
markTop
6 楼tdtjjiao(学习学习再学习)回复于 2005-05-08 09:56:24 得分 0
select * from table where a like '%''@反回的值 +'%'Top
7 楼zlp321002(Life Is Good,Let's Shine)回复于 2005-05-08 10:05:44 得分 0
--存储过程中是可以调用函数结果的!~Top




