Results 1 to 7 of 7
  1. #1
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401

    Unanswered: Urgent Help Needed

    Guys ...

    I need to import a flat file into a new table... and I need it to be done without using DTS .. preferably something command line ........

    Does anyone know how to carry this out

  2. #2
    Join Date
    Aug 2003
    Posts
    5

    Try bulk insert , BCP

    Try bulk insert , BCP

  3. #3
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Can you create a new table using BCP , Bulk insert ......... I dont think so .... and I dont think the BOL mentions that anywhere ....... BCP and Bulk insert are for inserting data into existing tables.

    I need a dynamic one where depending on the no of columns in the text file ... a table is created with same no of columns ..... i dont care if all the columns created are of varchar type

  4. #4
    Join Date
    Feb 2003
    Location
    Milano, Italy
    Posts
    80
    So, you have two possibilities:

    1) create a t-sql batch file
    2) create a vbscript file that uses sql-dmo

    in both cases you'll import data using the BULK INSERT function, after having created the table you need.
    Davide Mauri
    http://www.davidemauri.it

  5. #5
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    But how do i get to know the no of colums i have to create in TSQL ...
    I have not worked in VB and will not be able to use that

  6. #6
    Join Date
    Feb 2003
    Location
    Milano, Italy
    Posts
    80
    Well, in this case, if you cannot have help from someone that knows vbscript, you cannot read dinamically the number of columns from the text file.

    You can develop a stored procedure that will accept 2 parameters: filename and columns number.

    you'll pass that columns # manually, counting the columns by hand.

    Eg:

    stp_ImportData 'mytextfile.txt', 5
    Davide Mauri
    http://www.davidemauri.it

  7. #7
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    Well ......
    Solve dit myself
    did a thing better than that .......
    read all rows into a single column in a temp table and then used t-sql to count the no of rows using charindex and counting logic.


    However stuck on another problem

    incremental_table
    temp_table varchar 100
    table_name varchar 100
    created_date datetime 8
    created_by varchar 100

    transfer_increment_test
    optype varchar 2
    Tablename varchar 100
    deptno varchar 100
    dname varchar 100
    loc varchar 100

    increment_test
    deptno varchar 100
    dname varchar 100
    loc varchar 100


    based on optype in transfer_increment_test need to update , insert or delete in increment_test

    any suggestions
    .


    Last edited by Enigma; 08-18-03 at 06:04.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •