dbTalk Databases Forums  

Read file and EXEC contents

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Read file and EXEC contents in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Andre
 
Posts: n/a

Default Read file and EXEC contents - 03-23-2006 , 05:59 PM






I have a text file that contains "create index" statements - thanks to those
of you here who helped me get past my hurdles with this step earlier in the
week.

Now I need to read the file and execute it - basically execute the contents
of the file. I'm looking for suggestions on how to do it. I thought about
using the code below to read the contents into a global var but it seems as
if it only reads so many chars into a global var. My thought was to read it
into a global var then use an execute sql task to execute the global var.

Here is what I have so far. Any suggestion on the best way to apply the
create index statements in the text file?

Thanks, Andre

Function Main()

Set fso = CreateObject("Scripting.FileSystemObject")
Set textStreamObject = fso.OpenTextFile("c:\TableIndexes.txt",1,false,0)

' msgbox textStreamObject.ReadAll

DTSGlobalVariables("strIndexes").Value = textStreamObject.ReadAll

Set textStreamObject = Nothing
Set fso = Nothing

Main = DTSTaskExecResult_Success
End Function



Sample of my TableIndexes.txt file
ALTER TABLE [MYTABLE] ADD
CONSTRAINT [PK_MYTABLE] PRIMARY KEY CLUSTERED
(
[RowID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO







CREATE INDEX [prov_id] ON [MYTABLE]([Col1]) WITH FILLFACTOR = 90 ON
[PRIMARY]
GO



CREATE INDEX [ref_id] ON [MYTABLE]([Col2]) WITH FILLFACTOR = 90 ON
[PRIMARY]
GO



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.