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
- open file for reading
- choose the necessary data
- connect to the database
- enter the required data. What exactly is plugging?
|
- Right-click on the database in SSMS
- Import data
- choose source file Excel
- choose destination your database
- check mapping
- 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.
|