Saturday 15 May 2010

sql server - check if file exists then import using script task in SSIS -



sql server - check if file exists then import using script task in SSIS -

i have static table has has this: xy_jan10 yz_feb11 xx_march14 by_aug09 etc. these names static , stored in table. using foreachloop container, first reading , saving static names mentioned above scheme object variable. next using foreachloop containter , looping through each of file name , saving string variable called strfilename. in each loop container, have script task checks first if file exists , here have problem, each file name comes variable want check if file name exist firs, if exists want load table, if not exist want check next file name, if next file name not exist want check next variable name inline , on. want load if variable file name matches files on network drive, if not found want check next 1 until go through each 1 in static list names. issue script task stops when there no match file names want go next variable name in list , load because there lot of other matches not loaded. script task stops @ first 1 finds non much. here script task: please not files loading sas files.

public sub main() ' ' add together code here ' dim directory directoryinfo = new directoryinfo("\\840klm\datamart\cptt\cannon") dim file fileinfo() = directory.getfiles("*.sas7bdat") if file.length > 0 dts.variables("user::var_isfileexist").value = true else dts.variables("user::var_isfileexist").value = false end if dts.taskresult = scriptresults.success end sub

it looks need wrap script task within foreach loop container. there's plenty of info how on web, or on stack overflow: how loop through excel files , load them database using ssis package?

or

http://www.sqlis.com/sqlis/post/looping-over-files-with-the-foreach-loop.aspx

sql-server ssis sas

No comments:

Post a Comment