日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
sqlserver存儲過程使用實例

使用sql server存儲過程,可以在數(shù)據(jù)庫中實現(xiàn)多種功能,下面就為您介紹其中的一種,供您參考,希望對您學習sql server存儲過程的使用有所幫助。

如果需要同時插入N條數(shù)據(jù),不想在程序里控制,但是SQL Sever又不支持數(shù)組參數(shù).所以只能用變通的辦法了.利用SQL Server強大的字符串處理傳把數(shù)組格式化為類似"1,2,3,4,5,6",然后在sql server存儲過程中用SubString配合CharIndex把分割開來。

詳細的sql server存儲過程:

 
 
 
  1. CREATE PROCEDURE dbo.ProductListUpdateSpecialList  
  2.     @ProductId_Array varChar(800),  
  3.     @ModuleId int  
  4. AS  
  5.     DECLARE @PointerPrev int  
  6.     DECLARE @PointerCurr int  
  7.     DECLARE @TId int  
  8.     Set @PointerPrev=1 
  9.     set @PointerCurr=1 
  10.       
  11.     begin transaction  
  12.     Set NoCount ON  
  13.     delete  from ProductListSpecial where ModuleId=@ModuleId  
  14.       
  15.     Set @PointerCurr=CharIndex(',',@ProductId_Array,@PointerPrev+1)  
  16.     set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev,@PointerCurr-@PointerPrev) as int)  
  17.     Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)  
  18.     SET @PointerPrev = @PointerCurr  
  19.     while (@PointerPrev+1 < LEN(@ProductId_Array))  
  20.     Begin  
  21.         Set @PointerCurr=CharIndex(',',@ProductId_Array,@PointerPrev+1)  
  22.         if(@PointerCurr>0)  
  23.         Begin  
  24.             set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev+1,@PointerCurr-@PointerPrev-1) as int)  
  25.             Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)  
  26.             SET @PointerPrev = @PointerCurr  
  27.         End  
  28.         else  
  29.             Break  
  30.     End  
  31.       
  32.     set @TId=cast(SUBSTRING(@ProductId_Array,@PointerPrev+1,LEN(@ProductId_Array)-@PointerPrev) as int)  
  33.     Insert into ProductListSpecial (ModuleId,ProductId) Values(@ModuleId,@TId)  
  34.     Set NoCount OFF  
  35.     if @@error=0 
  36.     begin  
  37.         commit transaction  
  38.     end  
  39.     else  
  40.     begin  
  41.         rollback transaction  
  42.     end  
  43. GO  

新聞標題:sqlserver存儲過程使用實例
標題網(wǎng)址:http://www.5511xx.com/article/cdcegoi.html