declare test_cursor cursor for
select t1.baijiahao as bjh_name, t1.baijiahao_home_url as home_url, t2.category_name as domain from baijia_articles t1
inner join category t2
on t1.cat_id = t2.id
open test_cursor
declare @bjh_name nvarchar(50)
declare @home_url nvarchar(90)
declare @domain nvarchar(50)
fetch next from test_cursor into @bjh_name, @home_url, @domain
while @@fetch_status=0
begin
if not exists ( select id from baijiahao where bjh_name=@bjh_name) insert into baijiahao(bjh_name, home_url, domain) values(@bjh_name, @home_url, @domain)
fetch next from test_cursor into @bjh_name, @home_url, @domain
end
close test_cursor
deallocate test_cursor
sql server游标
发表评论