There is SQL server 2005 and C #. It is necessary to make several entries with Excell in the database. I want to copy these records to the clipboard and use C # to put them in the Base. How to do it? ATP in advance.

    3 answers 3

    1. open file for reading
    2. choose the necessary data
    3. connect to the database
    4. enter the required data. What exactly is plugging?
      1. Right-click on the database in SSMS
      2. Import data
      3. choose source file Excel
      4. choose destination your database
      5. check mapping
      6. Run immediatly ..

        You can convert data to SQL commands using AWK.

        Suppose you need to download phone numbers:

         Ivanov; Ivan; Ivanovich; 1965-01-01; +79272101010
         Petrov; Genadiy; Nikolaevich; 1980-01-18; +79272101894
         Nikolaeva; Zhanna; Aleksandrovna; 1991-12-24; +79273164132
        

        Contact table in database:

         TABLE contact (
           id bigint,
           type varchar (1024),
           contact varchar (1024),
           person_fk bigint
         )
        

        AWK script:

         {
          last_name = $ 1
          first_name = $ 2
          middle_name = $ 3
          birth_date = $ 4
          phone_number = $ 5
         }
         {
          printf "INSERT INTO contact (id, type, contract, person_fk) \ n \
             SELECT nextval ('id_seq'), 'PHONE', '% s', person.id FROM person \ n \
             WHERE \ n \
                     last_name = '% s' \ n \
                 and first_name = '% s' \ n \
                     and middle_name = '% s' \ n \
                     and birth_date = '% s' \ n \
                     and NOT EXISTS (SELECT 1 FROM contact WHERE \ n \
                         person_fk = person.id \ n \
                         and contact.type = 'PHONE' \ n \
                         and contact.contact = '% s' \ n \
                     );  \ n \
         ", phone_number, last_name, first_name, middle_name, birth_date, phone_number
         }
        

        With AWK, you can quickly and efficiently solve a wide range of tasks.