| Author |
Topic |
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 13:01:33
|
| I have a text file with 30 entries in it.I also have another text file with a 2 entries(the start date in mm/dd/yyyy and end date in same format)I have execute only access to a stored procedure on another database, which i execute and direct the output into a table i created in my local database.This is the 2 line script i execute:insert into Database.tablenameexec Servername.DatabaseName..storedprocedurename 'devicename', 'date'I have 30 device names and 5 days to collect datas for.So i keep changing the devices and dates to collect them all.Now i want to automate the entire process.So, i came up with the 2 text files i mentioned above.What i want to do is, a stored procedure should read the input from the device text file one by one and execute the above 2 insert and exec command and insert into table and repeat the process for 5 days and for all 30 devices.Hence I have a skeleton of a stored procedure which i am not sure is correct.Here it is.create procedure testAutomate@devicename varchar(50),@startdate datetime, @enddate datetimeASCREATE TABLE [dbo].[TestAutoAug31]( [systName] [varchar](50) NULL, [InterfaceName] [varchar](151) NULL, [SlotDateTime] [datetime] NULL, [InterfaceSpeed] [float] NULL, [LoadPctIn] [float] NULL, [LoadPctOut] [float] NULL, [deltaTime] [int] NULL, [InterfacesName] [varchar](151) NULL)beginwhile @enddate <= '08/31/2009'insert into Database.tablenameexec Servername.DatabaseName..storedprocedurename 'devicename', '@startdate'endWill this work?Here @ device name is the name it should fetch from the text file and date is the date it should fetch from the date text file.How will it fetch the data and input in this stored procedure.I have been reading many articles in vain.Please guide me.Thank you,Padhma |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-08-31 : 14:20:05
|
| any specific reason you want to use a text file? otherwise have a table with devicename and another with date, create a cursor and loop it a number of times to call the stored procedure. |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 14:29:19
|
| Hi Rohit,The reason is to edit the entries in the text file, without having to access the database often.But, as you said, I am trying to do that as an alternative.Tbl Test1 has one column with 30 entiries.Tbl Test2 has 1 column, 2 rows(2 dates)Tbl Test3 has 6 columns to insert the output of the stored procedure from exec ServerName.DBName..spname '@devicename', '@startdate'This is what i have...but it gives me rror saying the cursor is open or it does not exist, or does not exist.Please advice.declare @devicename varchar(50)declare @daterange datetimedeclare auto1 cursor forselect systName from Test1declare auto2 cursor forselect Daterange from Test2open auto1fetch next from auto1 into @devicenamewhile @@fetch_status = 0begin open auto2 fetch next from auto2 into @daterange while @@fetch_status = 0 begin insert into PadhmaUtilizData_Interface_PVZ.dbo.Test3 exec FTGBOSDASH2WIN.Network..spGetInterfaceData '@devicename', '@daterange' fetch next from auto2 into @daterange end close auto2 deallocate auto2fetch next from auto1 into @devicenameendclose auto1deallocate auto1Thank you,Padhma |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 16:05:30
|
| Any assistance here would be helpful. |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 16:37:20
|
| Hi Rohit,I followed that article and came up withthe cursor i wrote.Below is the modification and i get an error.error:Msg 8114, Level 16, State 5, Procedure spGetInterfaceData, Line 0Error converting data type varchar to smalldatetime.Cursor:declare @devicename varchar(50)declare @daterange varchar(50)declare auto1 cursor for select systName, Daterange from Test1, Test2open auto1fetch next from auto1 into @devicename, @daterangewhile @@fetch_status = 0begin insert into UtilizationData_PVZ.dbo.Test3 exec FTGBOSDASH2WIN.Network..spGetInterfaceData '@devicename', '@daterange'fetch next from auto1 into @devicename, @daterangeendclose auto1deallocate auto1 |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-31 : 16:43:08
|
make this select select systName, Daterange from Test1, Test2to see where the bad data is. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 16:45:55
|
| I do not see any bad data. I am seeing the exepcted 2 columns in the right format, DeviceName, 08/29/2009 |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 16:47:09
|
| if i execute the 2 sattement:insert into UtilizationData_PVZ.dbo.Test3exec FTGBOSDASH2WIN.Network..spGetInterfaceData 'DeviceName', '08/29/2009'It works fine. But when in a cursor it gives me error.error:Msg 8114, Level 16, State 5, Procedure spGetInterfaceData, Line 0Error converting data type varchar to smalldatetime. |
 |
|
|
rohitkumar
Constraint Violating Yak Guru
472 Posts |
Posted - 2009-08-31 : 16:50:56
|
| remove the quotesexec FTGBOSDASH2WIN.Network..spGetInterfaceData @devicename, @daterange |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-31 : 16:53:05
|
hm...please tryset language englishbefore your open cursor statement. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-31 : 16:54:17
|
quote: Originally posted by rohitkumar remove the quotesexec FTGBOSDASH2WIN.Network..spGetInterfaceData @devicename, @daterange
AAh Yes I didn't see!Good catch!! No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 17:00:25
|
| Thank you rohit. it worked now. |
 |
|
|
padhma.p
Yak Posting Veteran
91 Posts |
Posted - 2009-08-31 : 17:00:45
|
| Thank you webfred. |
 |
|
|
|