Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2002
    Location
    California, US
    Posts
    21

    Question Unanswered: How to read/select data from a text file in TLSQL

    Hello All,
    I wanna write a TSQl script which will read the data from a text file(having table like structure). Not with DTS, I wanna do this programatically as sql batch file. Kindly help me this is very urgent.
    Thanks in advance
    Thazul
    Last edited by thazanm; 12-10-02 at 18:44.

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Why is dts not an option ? Please provide a sample your data from the text file - is it delimited or fixed ?

  3. #3
    Join Date
    Jul 2002
    Posts
    229
    Is it possible to read a "csv" file?

    It is (as I've understood) via ODBC, but I guess ODBC won't help in this particular case?

  4. #4
    Join Date
    Jul 2002
    Location
    California, US
    Posts
    21

    Re: How to read/select data from a text file in TSQL

    Originally posted by thazanm
    Hello All,
    I wanna write a TSQl script which will read the data from a text file(having table like structure). Not with DTS, I wanna do this programatically as sql batch file. Kindly help me this is very urgent.
    Thanks in advance
    Thazul
    Thanks for ur reply.
    I wanna transfer data offline, so i cant use DTS. I am doing this offline data transfer using bcp(getting data from source database and making files then read from files and put it into target database). This is helpfull for me when the target database is fresh, when the target databse is having data, it need some validation for duplication, parent child relationship based on identity columns.

    All I want is, I am creating few file for each table using bcp with -c or
    -n option. After creating this I wanna read the data from created files to do some validation in TSQL and then load into target database.

    I mentioned offline mean, I am not sure what will be the target database and I am not sure about their database informations. This script has to go as a pre install script before our product get installed.

    I wanna put this in a simple way. In oracle there is Pl/SQL package available to open, read and write data from files to table and vice versa like UTL_FILE.<procedures>. Is there any functions or procedures available in SQLServer TSQL.

    Thanks in advance
    Thazul
    Last edited by thazanm; 12-11-02 at 14:11.

  5. #5
    Join Date
    Feb 2002
    Posts
    2,232
    You may have already mentioned why you can't do this - in situations like this I have a holding database and work with the data using tsql this way. Massage the data with a stored procedure and then output the data to the destination database/table.

  6. #6
    Join Date
    Jul 2002
    Location
    California, US
    Posts
    21

    How to read/select data from a text file in TLSQL

    Alrigth, I am sorry for the improper information provided.
    Well I am already having a TSQL script which will transfer data from one database to another database after doing all kind of validations. The isssue is doing it offline. I cant connect two database at the client place. Some client places the dont agree to connect with our database.
    I this facility(reading from files having table like data) is available then I can go for complete batch file.
    I really appricate ur suggestion, if anyone can provide me the syntax or comman, it will be great.

    Thanks in advance,
    Thazul

  7. #7
    Join Date
    Feb 2002
    Posts
    2,232
    Are you looking for a way to read in a file, run validations, then output the data to a file ?

  8. #8
    Join Date
    Oct 2002
    Posts
    369

    Question Re: How to read/select data from a text file in TLSQL

    RE:
    The isssue is doing it offline. I cant connect two database at the client place. Some client places the dont agree to connect with our database.
    In some situations one may attach an MDF file (pre-populated with the necessary data in tables), and subsequently use it as the staging area database for validation, transfer, etc. (to other DB targets). In this way the stageing area DB is effectively populated "off-line" (from a client perspective).

  9. #9
    Join Date
    Jul 2002
    Location
    California, US
    Posts
    21
    Originally posted by rnealejr
    Are you looking for a way to read in a file, run validations, then output the data to a file ?
    Hi,
    I am looking for reading the data from file and run validation and then store it into database tables.

    Thanks in advance

  10. #10
    Join Date
    Feb 2002
    Posts
    2,232
    I am confused as to why you can't use dts within your tsql - but you can accomplish this task by using bcp within your tsql, have your tsql validate and spit it out to a table(s).
    If this does not satisify your requirements, please let me know - a step by step detail of the entire process would be helpful- offline is a little vague at this point, since tsql implies online.

Posting Permissions

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