Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

SQL Server - Multiple insert

  • 27-11-2006 5:07pm
    #1
    Registered Users, Registered Users 2 Posts: 872 ✭✭✭


    Hi,

    I have a spreadsheet of about 600 values that need to be inserted into a table.
    The insertion can only be done through the query analyser so i cant use Enterprise manager to create
    a dts package (which i would normally do)

    Im wondering if i can put all these values into an array and jog through them and insert each one.

    Any ideas would be great.


Comments

  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'm assuming (probably incorrectly) that you're writing a sql script to insert them because you've said you have to use query analyser. Is this true? If so I'm not sure how you're going to use an array. Sounds like a cut and paste job to me. If so use a good text editor (or even a poor one) to insert the required SQL statements and then run that from QA.


  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Use the spreadsheet functionality to build a SQL INSERT for each row.

    If its Excel, for a 2-column insert you'd have something like the following in C1:

    ="INSERT into MyTable Values ('" & A1 & "', " & B1 & ")"

    Then copy-fill this down for your 600 rows, so the row value is auto-incrememnted in the formula for you.

    Then copy the 600 rows and paste the results into Query Analyzer.

    Note that I've assumed column A contains string data (hence the ' around it) where B contains numeric.

    This is the easiest (IMHO) one-off solution. If you need to automate, or do something more clever, then obviously you need to code a solution. Again, if its in Excel, some VBA would be your best bet.


  • Registered Users, Registered Users 2 Posts: 71 ✭✭zdragon


    ok guys verry funny:)
    so I think the better way will be to have data in CSV format, or any other structure like XML ..
    then use a simple SQL guery to read this CSV file and insert it in your table..
    don't mess with copy/paste and text editors.

    BULK INSERT bulktest..t_float
    FROM 'C:\t_float-c.dat' WITH (FORMATFILE='C:\t_floatformat-c-xml.xml');
    GO

    for more check with MSDN:http://msdn2.microsoft.com/en-us/library/ms188365.aspx


  • Registered Users, Registered Users 2 Posts: 872 ✭✭✭grahamor


    i knew there was a way to automate this.

    Thanks for all the replies though.


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Just use BCP . . . and change the file to csv. Will be in a jiffy


  • Advertisement
Advertisement