Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert a javascript array into a SQL table
    text
    copied!<p>Sorry for the vague title but I'm not sure at all how to go about this. I have a jquery auto complete text box on the page that allows users to search and add company names to a comma delimited list. I can use javascript to parse the values up and create an array of integers (id's for each company). When I do a javascript alert it will display the company ID's in an array of integers (9,20,19,17). The next step I have NO idea how to go about it how to get those into my insert stored procedure and loop through them with the scope_identity from the first table insert.</p> <p>Below is my current stored procedure. Right now I just have a hard coded supplier ID for the second insert but I need to be able to add a row for each selected company to the association table. So ideally it would loop through all four selected companies and add the company ID along with the scope identity from the insert on the nominations table. All the other data on the page will be added directly from asp.net controls and I don't know how to get the javascript array info over to the SP...Any guidance or direction would be greatly appreciated..</p> <pre><code>CREATE PROCEDURE dbo.NewNomination @ProviderFirstName VARCHAR (30)=NULL, @ProviderLastName VARCHAR (30)=NULL, @providerCompany VARCHAR (30)=NULL, @providerTitle VARCHAR (30)=NULL, @providerEmail VARCHAR (30)=NULL, @providerPhone VARCHAR (30)=NULL, @UseMyName BIT, @MakeCall BIT, @new_identity INT = NULL OUTPUT AS BEGIN SET NOCOUNT ON; INSERT INTO dbo.nomination ( ProviderFirstName , ProviderLastName , providerCompany , providerTitle , providerEmail , providerPhone , UseMyName , MakeCall ) VALUES ( @ProviderFirstName , @ProviderLastName , @ProviderCompany , @providerTitle , @providerEmail , @providerPhone , @UseMyName , @MakeCall ) SET @new_identity = SCOPE_IDENTITY(); INSERT INTO dbo.NominationSupplier ( NominationID , SupplierID , fname , lname , email ) VALUES ( @new_identity , 28 , @ProviderFirstName , @ProviderLastName , @providerEmail ) COMMIT TRAN END GO </code></pre> <p>`</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload