?
Solved

Append to a SQL table from an array

Posted on 2013-11-20
5
Medium Priority
?
290 Views
Last Modified: 2013-11-20
Is there a way to INSERT INTO a table from an array?

I do not have permissions for a BULK INSERT.

The array has 2 columns.

Col1 needs to be inserted into Col1 of the table.

Col2 needs to be inserted into Col2 of the table.

Can the array can be passed as a parameter into the stored procedure?

-- @arrExceptions  This is the 2 column array

      @SymbolID int,   -- From col1,row i of the array
      @Curr5DayAvg float, -- From col2,row i of the array


INSERT INTO Exceptions FROM the array.

(SymbolID, Curr5DayAvg)

VALUES (@SymbolID,@Curr5DayAvg)
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 39662675
I am not aware of the array being able to be passe from VB/VC# to the stored proc. However it is easy enough to write a
SQLCommand object with parameters such that you can loop

for (int i=0;i<whatever to of array is;i++) {
        'stuff ArrayName[i,0] into  into SQL command parameter variable
        'repead with ArrayName[i,1] into the second
         'Execute the SQL Command

         'repeat process
}

Here's an example:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar%28v=vs.110%29.aspx
0
 

Author Comment

by:Dovberman
ID: 39662935
I am doing something like this now.

The array has 1500 rows. It requires the sql statement to be executed 1500 times.

This times out the server.

Does the proposed method require the sql statement to be executed 1500 times?

 'Execute the SQL Command

         'repeat process
0
 
LVL 2

Accepted Solution

by:
Subhasree earned 2000 total points
ID: 39663341
An array cannot be passed as an arguement to a stored procedure.

If executing the sql command 1500 times is not practical for you,
You can write this in to xml file. Later execute a stored proced which reads the xml and insert the rows to the table without using BULK INSERT.
0
 

Author Comment

by:Dovberman
ID: 39663519
Thanks.  I will write the rows to an xml file.
0
 

Author Closing Comment

by:Dovberman
ID: 39663524
Thanks,

I will use the xml file approach.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question