views:

1058

answers:

3

Hi there,

I'm doing a project at the moment which involves using bulk insert to fill an sql table with weather data.

BULK INSERT TableWeather FROM 'C:\Program Files\EasyWeather\EasyWeather.dat' WITH (FIELDTERMINATOR = ',')

This seems to work fine but I need to do this every fifteen minutes and also actually overwrite the data from the last time so that the table size doesn't get out of control. I've been checking everywhere but Im not so handy with sql code. Do I need to create a stored procedure and automate that?

I also need to do it with a view to exporting the new data as an xml every fifteen minutes as well, which will be used by an swf for display on the asp.net website.

Any advice'd much appreciated, Thanks

A: 

Are you using SQL Server? If so you can use SSIS package to do this.

Help on SSIS --> link text

CodeToGlory
hi thanks for the tip but i'm using the express edition of visual web developer so i don't think I have SSIS, sounds like it would be the business though, cheers
Hi Emma, what database are you using currently to bulk insert?
CodeToGlory
Hi, I'm using an sql database in asp.net. it's a .mdf. database. Do you reckon I can use SSIS? Thanks
A: 

you can setup a Sql job or windws schedule job to run every 15 mins.. add a truncate statement before you do bulk insert.

Vikram Sudhini
Hey, Thanks for the advice, do you mean to create a stored procedure with the truncate statement and the bulk insert and then use an sql job to automate the stored proc then? Thanks
I would suggest this, yes.
eddiegroves
A: 

SQL Server still has the crusty old bcp utility, and the handy (relatively new) sqlcmd utility. Not sure if they're available for your version, but if they are, I would recommend it. You just put the bcp and sqlcmd statements in a Windows batch file and run them.

Something like this should work (you'll need to modify the switches on the commands)...

sqlcmd.exe -SMyServer -dMyDatabase -b -Q "delete from TableWeather"
bcp.exe MyDatabase.dbo.TableWeather in C:\Program Files\EasyWeather\EasyWeather.dat -SMyServer -T

See this link for more on bcp and this one for sqlcmd.

This may help you with your XML, too. Use sqlcmd to execute a stored proc that formats the data into XML and stores it in a table, and then use bcp to export it (bcp goes both ways.)

Hope this helps.

John M Gant