/*返回一个字符串中某一个字符第n次出现的位置的函数*/
create function f_firstposition(@Str varchar(8000),@Strsep varchar(10),@AppPos int)
returns int
begin
declare @i int
declare @ii int
set @Str=rtrim(ltrim(@Str))
set @i=1
select @ii=charindex(@StrSep,@Str)
if @i=@AppPos
return @ii
else
while @AppPos>@i
begin
if charindex(@StrSep,right(@Str,len(@Str)-@ii))<>0
select @ii=charindex(@StrSep,right(@Str,len(@Str)-@ii))+@ii
else
set @ii=0
set @i=@i+1
end
return @ii
endupdate 会计科目表 as a
set a.科目编码=b.sid
(select b.sid
case when class=1 then substring(b.sid,1,3)
when class=2 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,5,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)
when class=3 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',1)+1,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)+right(replicate('00',2)+
--
substring(b.sid,dbo.f_firstposition(b.sid,'.',2)+1,dbo.f_firstposition(b.sid,'.',3)-1-dbo.f_firstposition(b.sid,'.',2)),2)
when class=4 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',1)+1,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)+right(replicate('00',2)+
--
substring(b.sid,dbo.f_firstposition(b.sid,'.',2)+1,dbo.f_firstposition(b.sid,'.',3)-1-dbo.f_firstposition(b.sid,'.',2)),2)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',3)
--
+1,dbo.f_firstposition(b.sid,'.',4)-1-dbo.f_firstposition(b.sid,'.',3)),2)FROM [ZJZX].[ACCOUNTSECTIONS] as b
)
where a.帐套=b.setid
a.科目名称=b.ABBREVIATION
a.科目全称=b.name
a.科目级别=b.class
[/code]
create function f_firstposition(@Str varchar(8000),@Strsep varchar(10),@AppPos int)
returns int
begin
declare @i int
declare @ii int
set @Str=rtrim(ltrim(@Str))
set @i=1
select @ii=charindex(@StrSep,@Str)
if @i=@AppPos
return @ii
else
while @AppPos>@i
begin
if charindex(@StrSep,right(@Str,len(@Str)-@ii))<>0
select @ii=charindex(@StrSep,right(@Str,len(@Str)-@ii))+@ii
else
set @ii=0
set @i=@i+1
end
return @ii
endupdate 会计科目表 as a
set a.科目编码=b.sid
(select b.sid
case when class=1 then substring(b.sid,1,3)
when class=2 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,5,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)
when class=3 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',1)+1,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)+right(replicate('00',2)+
--
substring(b.sid,dbo.f_firstposition(b.sid,'.',2)+1,dbo.f_firstposition(b.sid,'.',3)-1-dbo.f_firstposition(b.sid,'.',2)),2)
when class=4 then substring(b.sid,1,3)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',1)+1,dbo.f_firstposition(b.sid,'.',2)-1-dbo.f_firstposition(b.sid,'.',1)),2)+right(replicate('00',2)+
--
substring(b.sid,dbo.f_firstposition(b.sid,'.',2)+1,dbo.f_firstposition(b.sid,'.',3)-1-dbo.f_firstposition(b.sid,'.',2)),2)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',3)
--
+1,dbo.f_firstposition(b.sid,'.',4)-1-dbo.f_firstposition(b.sid,'.',3)),2)FROM [ZJZX].[ACCOUNTSECTIONS] as b
)
where a.帐套=b.setid
a.科目名称=b.ABBREVIATION
a.科目全称=b.name
a.科目级别=b.class
[/code]
解决方案 »
- sqlserver与sqlite
- 怪了,我从没遇见过这种怪事----安装 SQL Server2000
- 急问:sqlserver 2000 reporting service 版本问题!!!
- 怎么设置在一个数据库表中有两个主键呀?
- 求sql定时发送数据存储过程的写法,在线等,谢谢!
- 我做了一个ssis包,里面只有一个ftp连接任务,测试正常,可是一加入作业执行就报错
- 为什么我的数据库登陆总是失败?
- image数据传输问题!
- 急!SQL启动问题
- sql server 如何将一列的数据以行的形式显示。具体请看。
- select多表查询疑难杂症
- Java [SQL Server]为过程或函数 pr_buildTest 指定的参数太多。
set ....
from 会计科目表 as a, (select .... from ) as b
where a.[] = b.[] and ...
是不是我写的自定义函数后用update就报错额?
--
substring(b.sid,dbo.f_firstposition(b.sid,'.',2)+1,dbo.f_firstposition(b.sid,'.',3)-1-dbo.f_firstposition(b.sid,'.',2)),2)+right(replicate('00',2)+ substring(b.sid,dbo.f_firstposition(b.sid,'.',3)
--
+1,dbo.f_firstposition(b.sid,'.',4)-1-dbo.f_firstposition(b.sid,'.',3)),2)
楼主.大概看了一下.你检查一下你的"括号"是不是对应的!
create function f_firstposition(@Str varchar(8000),@Strsep varchar(10),@AppPos int)
returns int
begin
declare @i int
declare @ii int
set @Str=rtrim(ltrim(@Str))
set @i=1
select @ii=charindex(@StrSep,@Str)
if @i=@AppPos
return @ii
else
while @AppPos>@i
begin
if charindex(@StrSep,right(@Str,len(@Str)-@ii))<>0
select @ii=charindex(@StrSep,right(@Str,len(@Str)-@ii))+@ii
else
set @ii=0
set @i=@i+1
end
return @ii
endupdate [text].[ZJZX].[ACCOUNTSECTIONS]
set sid =case when class=1 then substring(sid,1,3)
when class=2 then substring(sid,1,3)+right(replicate('00',2)+ substring(sid,5,dbo.f_firstposition(sid,'.',2)-1-dbo.f_firstposition(sid,'.',1)),2)
when class=3 then substring(sid,1,3)+right(replicate('00',2)+ substring(sid,dbo.f_firstposition(sid,'.',1)+1,dbo.f_firstposition(sid,'.',2)-1-dbo.f_firstposition(sid,'.',1)),2)+right(replicate('00',2)+
substring(sid,dbo.f_firstposition(sid,'.',2)+1,dbo.f_firstposition(sid,'.',3)-1-dbo.f_firstposition(sid,'.',2)),2)
when class=4 then substring(sid,1,3)+right(replicate('00',2)+ substring(sid,dbo.f_firstposition(sid,'.',1)+1,dbo.f_firstposition(sid,'.',2)-1-dbo.f_firstposition(sid,'.',1)),2)+right(replicate('00',2)+
substring(sid,dbo.f_firstposition(sid,'.',2)+1,dbo.f_firstposition(sid,'.',3)-1-dbo.f_firstposition(sid,'.',2)),2)+right(replicate('00',2)+ substring(sid,dbo.f_firstposition(sid,'.',3)
+1,dbo.f_firstposition(sid,'.',4)-1-dbo.f_firstposition(sid,'.',3)),2)end这个问题解决了,但是运行的时候还是出现update语法错误,