sql语句里能否包含自定义函数

cndeath 2008-04-08 10:56:28

left
mid

function str()
....
end function

...全文
131 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
正宗老冉 2008-04-09
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 cndeath 的回复:]
Sql = "select * from tb where dbo.f_GotTopic(content,3)='123'"
这样不行.
我想要这样的效果.
[/Quote]

完全可以。
上面不行是 EXEC Sql 的引号问题。
cndeath 2008-04-08
  • 打赏
  • 举报
回复
Sql = "select * from tb where dbo.f_GotTopic(content,3)='123'"
这样不行.
我想要这样的效果.
cndeath 2008-04-08
  • 打赏
  • 举报
回复
我试的不行啊.
cndeath 2008-04-08
  • 打赏
  • 举报
回复
iamme81 你的意思建存储过程?

Function GotTopic(Str,StrLen)
Dim l,t,c, i,LableStr,regEx,Match,Matches
If StrLen=0 then
GotTopic=""
exit function
End If
if IsNull(Str) then
GotTopic = ""
Exit Function
end if
if Str = "" then
GotTopic=""
Exit Function
end If
Str=Replace(Replace(Replace(Replace(Str," "," "),""",Chr(34)),">",">"),"<","<")
l=len(str)
t=0
strlen=Clng(strLen)
for i=1 to l
c=Abs(Asc(Mid(str,i,1)))
if c>255 then
t=t+2
else
t=t+1
end if
if t>=strlen then
GotTopic=left(str,i)
exit for
else
GotTopic=str
end if
Next
GotTopic = Replace(Replace(Replace(Replace(GotTopic," "," "),Chr(34),"""),">",">"),"<","<")
End Function

这样的一个子程序行不?
iamme81 2008-04-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 iamme81 的回复:]
引用 4 楼 cndeath 的回复:
str() 判断字符串的长度汉字为2,字母,数字为1

select content from tb where dobo.f_str(content) <100

这样吗?

可以
[/Quote]
不过那个dobo是啥?
要写成DBO吧
iamme81 2008-04-08
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 cndeath 的回复:]
str() 判断字符串的长度汉字为2,字母,数字为1

select content from tb where dobo.f_str(content) <100

这样吗?
[/Quote]
可以
iamme81 2008-04-08
  • 打赏
  • 举报
回复
完全能,比如
create table str
(str int)

while 1=1
insert str values(RAND()*1000)

create function dbo.FN_Discount(@discount int)
returns int
begin
if @discount=0
begin
set @discount=1
end
return @discount
end


select dbo.FN_Discount(str) from str

select * from str where dbo.FN_Discount(str)=1

cndeath 2008-04-08
  • 打赏
  • 举报
回复
str() 判断字符串的长度汉字为2,字母,数字为1

select content from tb where dobo.f_str(content)<100

这样吗?
Limpire 2008-04-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 happyflystone 的回复:]
引用 1 楼 dawugui 的回复:
可以调用:

select dbo.f_yourfunc(列id) from tb

[/Quote]
-狙击手- 2008-04-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 dawugui 的回复:]
可以调用:

select dbo.f_yourfunc(列id) from tb
[/Quote]
dawugui 2008-04-08
  • 打赏
  • 举报
回复
可以调用:

select dbo.f_yourfunc(列id) from tb

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧