Passing non-scalar data for multiple columns using runstoredprocedure

1 回表示 (過去 30 日間)
sst
sst 2023 年 9 月 11 日
コメント済み: sst 2023 年 10 月 5 日
Hello, I am trying to pass non-scalar data into an SQL Server stored procedure using the "runstoredprocedure" function in the Database Toolbox. The syntax for doing so was not very clear. How should we proceed? The data may be associated with multiple columns.
The stored procedure itself is written as follows:
-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE dbo.pc_NewRecord_tb_SerialNumberList
-- Add the parameters for the stored procedure here
@SerialNumberList aSerialNumberList READONLY
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO dbo.tb_SerialNumberList(serial_number)
SELECT * FROM @SerialNumberList
END
GO
where aSerialNumberList is a user-defined table type, with a single column: serial_number (nvarchar(32)).
What's the correct call to "runstoredprocedure" to pass in a cell array of chars or a string array? Also, how would this syntax be extended to multiple columns (e.g. if aSerialNumberList had more than one column)?

回答 (1 件)

Sachin Lodhi
Sachin Lodhi 2023 年 10 月 5 日
Hi,
Based on my understanding, it seems that you are seeking guidance on how to pass non-scalar data to a stored procedure. The syntax for achieving this is as follows:
runstoredprocedure(c,'myproc',{2500,'Jones'});
In this example, 'c' represents the connection object, 'myproc' is the name of the procedure, and 2500 and 'Jones' are the values to be inserted into the table.
To pass a cell array of chars or a string array, you can simply specify them as comma-separated values within the curly braces, similar to the code snippet provided above.
For additional insights and alternative approaches, please refer to following MATLAB Answers:
I hope this helps.
Best Regards,
Sachin
  1 件のコメント
sst
sst 2023 年 10 月 5 日
Hello Sachin, I believe that syntax still inserts one row of data. What I am looking to do is essentially insert a block of data. The alternative would be to call "runstoredprocedure" in a loop, but I was hoping to avoid that.
Regards.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDatabase Toolbox についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by