Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Get Filename and import fixed width file

Get Filename and import fixed width file

Scheduled Pinned Locked Moved Database
databasesql-serverquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    ReallyDumbDudee
    wrote on last edited by
    #1

    I just not wanting to recreate the wheel here. I need to do the following: 1.Get two parts of the filename to use wihtin the sql. The filename look like this some name here.123456.1.txt I need the 1 and the 123456 to populate two columns within the database table along with the data from the text file. the text file is fixed width 1-9 is the first column 10-18 the second column etc. I have around five hundred of these txt files I will need to loop through an process. has anyone done anything like this is a stored proc not using ssis? many thanks

    L 1 Reply Last reply
    0
    • R ReallyDumbDudee

      I just not wanting to recreate the wheel here. I need to do the following: 1.Get two parts of the filename to use wihtin the sql. The filename look like this some name here.123456.1.txt I need the 1 and the 123456 to populate two columns within the database table along with the data from the text file. the text file is fixed width 1-9 is the first column 10-18 the second column etc. I have around five hundred of these txt files I will need to loop through an process. has anyone done anything like this is a stored proc not using ssis? many thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Open up a console-window ([Windows Key]-[R], type cmd, press enter) and execute below command;

      dir "C:\Windows\m*.log" /b >files.txt

      Replace my Windows location (and the wildcard) with one that's more appropriate for you. Next step is easy, you copy and paste it into MS Access. You now have a table with filenames. You could loop those in Access, and fetch the correct file and save it with some VBA-code. Then make a linked server (in Sql Server) to the Access database (one for generic imports like these) and simply copy the (appropriate) records over.

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      R 1 Reply Last reply
      0
      • L Lost User

        Open up a console-window ([Windows Key]-[R], type cmd, press enter) and execute below command;

        dir "C:\Windows\m*.log" /b >files.txt

        Replace my Windows location (and the wildcard) with one that's more appropriate for you. Next step is easy, you copy and paste it into MS Access. You now have a table with filenames. You could loop those in Access, and fetch the correct file and save it with some VBA-code. Then make a linked server (in Sql Server) to the Access database (one for generic imports like these) and simply copy the (appropriate) records over.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        R Offline
        R Offline
        ReallyDumbDudee
        wrote on last edited by
        #3

        Thank you for your reply. I need to be able to do all of thee above wihtin a stored proc without depending on any other app or tool. any thoughts? again thank you for your reply.

        L 1 Reply Last reply
        0
        • R ReallyDumbDudee

          Thank you for your reply. I need to be able to do all of thee above wihtin a stored proc without depending on any other app or tool. any thoughts? again thank you for your reply.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          None; yes, it could be done using a sproc. Yes, you can list directories, manipulate strings. How much of this sproc have you written yet?

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups