[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Append to a SQL table from an array

Posted on 2013-11-20
5
Medium Priority
?
295 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

656 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