use yqcz;
--=======把字符串转换成类数组方法,
begin
declare @arr varchar(50),@i int ,@arrAt char(50),@subArr varchar(100),@subArrIndexValue varchar(100)
-- declare @fzhsCursor cursor
declare @indexCursor varchar(100)
-- 被重新记录行数
declare @rowCount int
--定义查询到的科目代码和辅助代码
declare @KMCode varchar(100)
declare @FZHS VARCHAR(100)
-- 测试字符串
-- set @arr=',1,3,9,'
-- 循环角标
set @i=1
-- print @subArr
-- PRINT LEN(@arr)
-- 定义游标
declare FZHSCursor cursor FOR
--查询辅助核算代码
select distinct fzhs,KMDM from GL_KMXX where kjnd='2019' and kmdm like '2307%'and gsdm='907008103002'; -- FOR UPDATE;
--查询记录行数
set @rowCount=(select count(fzhs ) from GL_KMXX where kjnd='2019' and kmdm like '2307%'and gsdm='907008103002');
-- 打开游标
open FZHSCursor;
--检查是否有记录
if (@rowCount)>0
begin
--控制循环从1开始
if @i-2 < @rowCount
begin
--读取记录,将字段值赋予@FZHS, @KMCode
fetch next from FZHSCursor into @FZHS, @KMCode
PRINT @FZHS;
PRINT @KMCode;
IF @FZHS <>'' AND @FZHS<>NULL
BEGIN
--OPP
--去掉首尾逗号
set @arr=@FZHS;
set @subArr= SubString(LTRIM( @arr), @i+1,LEN(@arr)-2)
print @subArr;
set @i=@i+2;
END
ELSE PRINT '无辅助核算!';
end
-- break;
end
--关闭游标
-- close fzhsCursor;
end