惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
腾讯CDC
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
P
Proofpoint News Feed
雷峰网
雷峰网
博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
V
V2EX
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
S
SegmentFault 最新的问题

博客园 - 珂儿

谈话技巧 用户中心 - 博客园 用户中心 - 博客园 【转载】 正则表达式 致谢 转载:Prototype.js的中文使用手册 C# Program Output Redirect 猫猫感冒了 从我的衣着改变说起 天无绝人之路 Job hunting准备系列一——关于搜索引擎技术 读书疑问汇总 算法题目汇总 How to influence people and win friends 项目经历总结——IBM实习总结 C++程序设计学习笔记 求职经验汇总 《编程之美》笔记
Notes of Store Procedure
珂儿 · 2009-01-05 · via 博客园 - 珂儿

I have not done anything related to this knowledge before, so this time I have met with many questions and problems when I have to use store procedure to finish some database operation. In order to make myself know more, I note down some thing here firstly and I would try to refine these materials to a real note if I had sometime in future.

CREATE PROCEDURE [dbo].[zhangke]

AS

BEGIN

declare @tempOfferId char(50)

declare @topCats varchar(200)

declare @subCats varchar(300)

DECLARE rs CURSOR LOCAL SCROLL FOR

select offer_id from compare_task_detail_result

open rs

fetch next from rs into @tempOfferId

WHILE @@FETCH_STATUS = 0

Begin

select @topCats = Category,@subCats = ItemProviderCategory from [JellyFish].[dbo].[20080922] where Id=@tempOfferId

update compare_task_detail_result

set offer_category=@topCats,offer_ItemProviderCategory=@subCats

where offer_id = @tempOfferId

fetch next from rs into @tempOfferId

end

close rs

END

USE [temp]

GO

/****** Object: StoredProcedure [dbo].[updateTempTable] Script Date: 01/06/2009 12:57:25 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[updateTempTable]

@tbname varchar(100)

AS

BEGIN

declare @tempOfferId char(50)

declare @topCats varchar(200)

declare @subCats varchar(300)

declare @sqlStr nvarchar(1000)

DECLARE rs CURSOR LOCAL SCROLL FOR

select offer_id from compare_task_detail_result

open rs

fetch next from rs into @tempOfferId

WHILE @@FETCH_STATUS = 0

Begin

set @sqlStr=' select @topCats = Category,@subCats = ItemProviderCategory from ' + @tbname + ' where Id='+@tempOfferId;

EXEC SP_EXECUTESQL @sqlStr,N'@topCats varchar(200) out,@subCats varchar(300) out', @topCats out,@subCats out

update compare_task_detail_result

set offer_category=@topCats,offer_ItemProviderCategory=@subCats

where offer_id = @tempOfferId

fetch next from rs into @tempOfferId

end

close rs

END

USE [temp]

GO

/****** Object: StoredProcedure [dbo].[updateTempTable2] Script Date: 01/06/2009 16:39:04 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[updateTempTable2]

--@tbname varchar(1000)

AS

BEGIN

declare @tempOfferId char(50)

declare @topCats varchar(200)

declare @subCats varchar(300)

declare @sqlStr nvarchar(1000)

DECLARE rs CURSOR LOCAL SCROLL FOR

select offer_id from compare_task_detail_result

open rs

fetch next from rs into @tempOfferId

WHILE @@FETCH_STATUS = 0

Begin

--set @sqlStr=' select @topCatsOut = Category,@subCatsOut = ItemProviderCategory from ' + @tbname + ' where Id='+@tempOfferId;

--EXEC SP_EXECUTESQL @sqlStr,N'@topCatsOut varchar(200) OUTPUT,@subCatsOut varchar(300) OUTPUT', @topCatsOut = @topCats OUTPUT,@subCatsOut = @subCats OUTPUT

select @topCats = Category,@subCats = ItemProviderCategory from [JellyFish].[dbo].[20080922] where Id=@tempOfferId

update compare_task_detail_result

set offer_category=@topCats,offer_ItemProviderCategory=@subCats

where offer_id = @tempOfferId

fetch next from rs into @tempOfferId

end

close rs

END