0

I want to create a SQL Server 2012 Stored Procedure that will take an array from PHP as an IN parameter.

The table that the procedure will insert into is called dbo.Users and it will have three columns that I care about: createdby, userid, emailaddress

The array will include userid and email address. It call will include one OR more records to insert into the Users table.

How do I get the procedure to accept an array and how do I turn the array into multiple insert statements into my Users table? Do I need to use table value parameters? I heard of them but haven't used one before.

Thank you!

AAA
  • 2,388
  • 9
  • 32
  • 47
  • Yes, you'd better use [table-valued parameter](https://msdn.microsoft.com/en-AU/library/bb510489.aspx). In the stored procedure there will be one `INSERT` statement that inserts all rows from the passed table-valued parameter at once. – Vladimir Baranov Apr 06 '16 at 22:48
  • Thank you @VladimirBaranov - the example on that page seems simple. How does it actually handle an array though? – AAA Apr 06 '16 at 22:58
  • I don't understand what is your problem. Array is a table. Table is array. Go through examples in the MSDN and if you have a specific question - ask here. – Vladimir Baranov Apr 06 '16 at 23:34
  • you can follow the suggestion provided by @VladimirBaranov or you can read this article in order to implement an xml for the operation [Link](https://www.mssqltips.com/sqlservertip/2899/importing-and-processing-data-from-xml-files-into-sql-server-tables/) – jthalliens Apr 07 '16 at 01:40

1 Answers1

0

You can use XML parameter to pass a set / list(s) of related data to a stored procedure, or you can use Table valued parameter.

Abdul Rasheed
  • 6,486
  • 4
  • 32
  • 48