虽然SELECT id, also FROM names WHERE isnull(also,'')<>''1返回的结果超过2000,但是以下游标未循环,但我得到了:
@count = 0
码:
DECLARE @id BIGINT, @name NVARCHAR(1000)
DECLARE @aslo TABLE (id INT, name NVARCHAR(100))
DECLARE name_cur CURSOR FOR
(SELECT id, also
FROM names
WHERE ISNULL(also, '') <> '')
DECLARE @count INT = 0
OPEN name_cur
WHILE @@FETCH_STATUS = 0
BEGIN
SET @count = @count + 1
INSERT INTO @aslo (id, name)
SELECT @id, *
FROM string_split(@name, ',')
FETCH NEXT FROM name_cur INTO @id, @name;
END
CLOSE name_cur;
DEALLOCATE name_cur;
SELECT @count
SELECT COUNT(*) FROM @aslo a
我认为在没有光标的情况下执行此操作要简单得多。这似乎等效于您要执行的操作:
INSERT INTO @aslo (id, name)
SELECT n.id, ss.value as name
FROM names n CROSS APPLY
string_split(n.name, ',') ss;
这是db <>小提琴。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。