2000 和2005 的区别

studyking 2008-11-18 05:52:11
select distinct b.* from a b,a c where
b.id=c.id
and (select count (*) from f_split(a.sid,','))>0

f_split是网上找的一个split函数。这句话在sql server 2005 执行没有问题,但是在2000下有问题 。
我把2000下的数据库附加到2005也是出现问题。我在2005直接创建表 执行的话什么问题都没有
...全文
191 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
dobear_0922 2008-11-19
  • 打赏
  • 举报
回复
少了表别名:
select distinct b.* from a b,a c where
b.id=c.id
and (select count (*) from f_split(a.sid,',') tb)>0
fcuandy 2008-11-19
  • 打赏
  • 举报
回复
and (select count (*) from dbo.f_split(a.sid,',') x)>0
studyking 2008-11-19
  • 打赏
  • 举报
回复
直接调用是没有问题的。就是嵌套到select 里面的时候有问题的。写成固定的一是没有问题的
studyking 2008-11-19
  • 打赏
  • 举报
回复
ALTER function [dbo].[f_split](@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin
while(charindex(@split,@c)<>0)
begin
insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
dawugui 2008-11-18
  • 打赏
  • 举报
回复
--2000下的.

/*
功能:实现split功能的函数
*/

create function dbo.fn_split
(
@inputstr varchar(8000),
@seprator varchar(10)
)
returns @temp table (a varchar(200))
as

begin
declare @i int

set @inputstr = rtrim(ltrim(@inputstr))
set @i = charindex(@seprator, @inputstr)

while @i >= 1
begin
insert @temp values(left(@inputstr, @i - 1))

set @inputstr = substring(@inputstr, @i + 1, len(@inputstr) - @i)
set @i = charindex(@seprator, @inputstr)
end

if @inputstr <> '\'
insert @temp values(@inputstr)

return
end
go

--调用

declare @s varchar(1000)

set @s='1,2,3,4,5,6,7,8,55'

select * from dbo.fn_split(@s,',')

drop function dbo.fn_split
ws_hgo 2008-11-18
  • 打赏
  • 举报
回复
看下那个函数
水族杰纶 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sdhylj 的回复:]
SQL code
--try
select distinct b.* from a b,a c where
b.id=c.id
and (select count (*) from dbo.f_split(a.sid,','))>0
[/Quote]
很可能是这个原因
调用函数加上所有者dbo.f_split()
水族杰纶 2008-11-18
  • 打赏
  • 举报
回复
把f_split函数贴出来看看
问题 应该在这里
CN_SQL 2008-11-18
  • 打赏
  • 举报
回复
参见我在你的另一帖子里的回复。
http://topic.csdn.net/u/20081118/17/912472d1-5477-4eac-9148-b8be554063b8.html?seed=919138796
csdyyr 2008-11-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sdhylj 的回复:]
SQL code--tryselectdistinctb.*froma b,a cwhereb.id=c.idand(selectcount(*)fromdbo.f_split(a.sid,','))>0
[/Quote]
.
青锋-SS 2008-11-18
  • 打赏
  • 举报
回复

--try
select distinct b.* from a b,a c where
b.id=c.id
and (select count (*) from dbo.f_split(a.sid,','))>0

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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