久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在存儲過程中為同一變量傳遞多個值

Passing multiple values for same variable in stored procedure(在存儲過程中為同一變量傳遞多個值)
本文介紹了在存儲過程中為同一變量傳遞多個值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個將多個值傳遞給存儲過程的變量.

I have a variable that passes multiple values to stored procedure.

當我看穿 fidler 時,我看到值像

When I see through fidler I see values being passed correctly like

    arg1=331
    arg1=222
    arg1=876
    arg1=932

在我的存儲過程中,我讀為

In my stored procedure I am reading as

    procedure mainValues 
     @Arg1List     nvarchar(3000)
    as begin
  --Temp table to store split values
  declare @tmp_values table (
  value nvarchar(255) not null);   

   --function splitting values 
   insert into @tmp_values 
   select * from f_split(@Arg1List, ',');  

  --inserting in table value column is int.      
  insert into t_values (
   value
  )
  select 
  b.value
  from @tmp_values b;

當我測試它時,它不會在 t_values 表中添加任何值.我檢查了功能等都工作正常.問題是@Arg1List.看起來存儲過程中沒有值.請讓我知道如何正確聲明 @Arg1List 以便它采用多個值,因為它似乎是問題所在.

When I test it, it doesn't add any values in t_values table. I checked the function etc. are all working fine. The problem is @Arg1List. It looks like stored procedure has no values in it. Please let me know how to declare @Arg1List properly so it takes multiple values as it seems to be the problem.

推薦答案

您需要做一些事情來實現這一點,因為您的參數正在獲取多個值,您需要創建一個表類型并制作您的存儲過程接受該類型的參數.

You will need to do a couple of things to get this going, since your parameter is getting multiple values you need to create a Table Type and make your store procedure accept a parameter of that type.

當您獲得包含多個值的 One String 時,拆分函數效果很好,但是當您傳遞多個值時,您需要做這樣的事情....

Split Function Works Great when you are getting One String containing multiple values but when you are passing Multiple values you need to do something like this....

表格類型

CREATE TYPE dbo.TYPENAME AS TABLE 
 (
    arg int 
  )
 GO

接受該類型參數的存儲過程

 CREATE PROCEDURE mainValues 
 @TableParam TYPENAME READONLY
 AS 
   BEGIN
    SET NOCOUNT ON;
  --Temp table to store split values
  declare @tmp_values table (
  value nvarchar(255) not null);   

   --function splitting values 
   INSERT INTO @tmp_values (value)
   SELECT arg FROM @TableParam


   SELECT * FROM @tmp_values  --<-- For testing purpose
END

執行過程

聲明一個該類型的變量并用您的值填充它.

Declare a variable of that type and populate it with your values.

 DECLARE @Table TYPENAME     --<-- Variable of this TYPE

 INSERT INTO @Table                --<-- Populating the variable 
 VALUES (331),(222),(876),(932)

EXECUTE mainValues @Table   --<-- Stored Procedure Executed 

結果

╔═══════╗
║ value ║
╠═══════╣
║   331 ║
║   222 ║
║   876 ║
║   932 ║
╚═══════╝

這篇關于在存儲過程中為同一變量傳遞多個值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 久久最新网址 | 国产高清免费视频 | 国产精品爱久久久久久久 | 一区二区av | 中文字幕 国产精品 | 精品久久久一区 | 精品国产一区二区国模嫣然 | 国产一级在线观看 | 国产激情精品视频 | 亚洲高清三级 | 91欧美| 国产一区二区在线视频 | 天天久久 | 一级毛片免费 | 国产精品大片 | 伊人电影院av | 国产亚洲网站 | 国产东北一级毛片 | 成人精品毛片国产亚洲av十九禁 | 国产一级特黄视频 | 欧美涩| 久久99久久| 亚洲一区 中文字幕 | 美女久久久 | 久久久久国产精品一区二区 | 91九色婷婷 | 亚洲精品电影网在线观看 | 农村真人裸体丰满少妇毛片 | 久久久影院 | 精品成人在线观看 | 国产我和子的乱视频网站 | 欧美日韩中文在线 | 日韩在线免费视频 | 欧美一区2区三区3区公司 | jizz中国日本 | 亚洲一区二区三区四区在线观看 | 亚洲国产一区二区视频 | 亚洲精品视频一区二区三区 | 国产精品成人一区二区三区夜夜夜 | 综合自拍 | 午夜在线观看免费 |