Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How can I read an ini file using transact-sql?

Author  Topic 

PaTRiCKDRD
Yak Posting Veteran

55 Posts

Posted - 2003-11-24 : 13:17:05
How can I read an ini file in order to do a multiplication? I know how to do that in Visual Basic 6, but what about SQL Server? I need to read that .ini file and get the values in a column. How can I do this?

nr
SQLTeam MVY

12543 Posts

Posted - 2003-11-24 : 14:28:48
create table ##a (s varchar(1000))
bulk insert ##a from 'c:\myfile.ini' with (FIELDTERMINATOR='|', ROWTERMINATOR = '\n')



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

CtrlAltDel
Starting Member

17 Posts

Posted - 2003-11-24 : 14:47:05
But I doubt that that would work if the .INI file were in the traditional format:

[category]
Value1=x
Value2=y

You could write an Extended Procedure, that uses sp_OACreate to play around with the Scripting.FileSystemObject to read it in.

Of course, once Yukon gets here, it will be *so* much easier

--
David Keaveny
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-24 : 14:56:58
why is this stuff stored in an INI file? A database table is a pretty good place to store settings !!


- Jeff
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-11-24 : 15:02:02
>> But I doubt that that would work if the .INI file were in the traditional format:
An ini file is just a text file so it should read in all the data and allow you to extract values from it.
Try it and see.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

PaTRiCKDRD
Yak Posting Veteran

55 Posts

Posted - 2003-11-25 : 10:11:11
My .ini file is like this guys:

[210*,]
flat1=*=0.00098

[69*,]
flat1=*=0.003966

[222*,223*,226*,2263*,224*,225*,231*,233*,238*,239*,242*,243*,244*,246*,249*,252*,255*,259*,261*,262*,263*,267*,265*,269*,266*,271*,273*,274*,275*,276*,279*,281*,282*,283*,284*,289*,]
flat1=*=0.0014076

So, I need two columns, one for the [210*,] and the other for flat1=*=0.00098 for example. How can this be done?
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-25 : 10:15:18
why are you using INI files? why not store this information in your database?

- Jeff
Go to Top of Page

PaTRiCKDRD
Yak Posting Veteran

55 Posts

Posted - 2003-11-25 : 10:21:14
Since it's done, what can I do now to get the data from that .ini file to a table in the database?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-11-25 : 22:48:48
Why not just enter it by hand? You'll spend at least as much time trying to find another way to do it. Once it's in the database, lose the ini files.
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-11-26 : 08:34:47
I totally agree with Rob, that's what I was getting at when I suggested a differnet way of storing this info.

Unless some client or someone is generating these things by some process and you need to import them into your database on a periodic basis, just do the 1-time hand entry and you are good to go. Even the "Yak Gurus" here at SQLTeam have to do a little manual data entry now and then !

If they ARE being generated, then I highly recommend a different (easier to import) format.

- Jeff
Go to Top of Page

PaTRiCKDRD
Yak Posting Veteran

55 Posts

Posted - 2003-11-26 : 09:55:39
Thanks Jeff. I just need to import them (this data is the charge per second), in order to multiply them with the time of each call and get the cost. All that will be published on the internet, so I created a VB project which exports this data on a flexgrid, which project I hope I can convert to VB script in order to show the results to the internet explorer file.
Go to Top of Page

PaTRiCKDRD
Yak Posting Veteran

55 Posts

Posted - 2004-05-27 : 11:23:08

Oracle has a text_io package, by which you can read and write text files. What about SQL Server guys?

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-05-27 : 14:23:31
Just a thought: For a one-off job, use a decent text editor to change the INI file so that the data is on one line, separated by, say, a TAB. So:

[210*,]<TAB>flat1=*=0.00098
[69*,]<TAB>flat1=*=0.003966

Strip out any blank lines too.

Then import as a delimited file (using DTS or whatever)

Kristen
Go to Top of Page
   

- Advertisement -