Advertisement

03.25.2008 at 03:00PM PDT, ID: 23268811
[x]
Attachment Details

Read contents of text file into Global Variable

Asked by SWRO in MS SQL DTS, Visual Basic Programming, ActiveX

Tags: Microsoft, SQL Server, 2000, DTS

I am trying to set up a DTS package that can dynamically change the SQLSourceStatement in a DTS Data Pump based upon a user's selection.

So, if user selects option 1 (via InputBox in ActiveX task), then I want to be able to read the entire SQL string found in a text file (on the network) into a variable. That variable would then be used as the SQLSourceStatement in the Data Pump. However, I am having issues reading the attached into a variable - I just get a bunch of blanks and/or weird characters when I try to use the FileScriptingObject.

Pseudo:
User is presented with option regarding type of query - all are similar, but slightly different.
User makes selection
Based upon selection, a specific TXT or SQL file is selected from a Network Share
The file is opened and the contents of that file are read into a variable
That variable is used to define the Data Pump SQLSourceStatement

Any ideas?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
-- This is an example of the SQL string found in the TXT/SQL file
SELECT DATE_FORMAT(m.created_at, '%y%m%d') 'entrydate'
 ,m.member_id
 ,n.full_name 'name1'
 ,n.main_phone2
 ,n.address1
 ,n.city
 ,s.abbreviation
 ,n.postal_code2
 ,n.email
 ,u.fullname 'user'
FROM db1.members m
 JOIN db1.names n ON m.id = n.member_id
 JOIN db1.states s ON n.state_id = s.id
 JOIN db1.users u ON m.user_id = u.id
WHERE m.partner_id = 4
 AND m.sub_partner_id != 3
 AND n.name_type_id = 1
 AND m.expiration_date > DATE_ADD(CURRENT_DATE(), INTERVAL -18 MONTH);
--------------------------------------------------------------------
-- This is an example of the VBScript found in the ActiveX task
Function Main()
	Dim oPkg
	Dim oDataPump
	Dim sSQL
	Dim choice
	Dim path
 
	sSQL = "TESTING"
	path = ""
 
 
	'// Prompt user for input - need to flesh this out
         choice = InputBox("Select a query")
 
	SELECT CASE choice
		CASE 1
			path = "\\Server\Share\qry_Text1.txt"
		CASE 2
			path = "\\Server\Share\qry_Text2.txt"
		CASE ELSE
			path = "\\Server\Share\qry_Text0.txt"
	END SELECT
	
	'// Get reference to the DataPump Task
	Set oPkg = DTSGlobalVariables.Parent
	Set oDataPump = oPkg.Tasks("DTSTask_DTSDataPumpTask_1").CustomTask
 
	'// Get the SQL string from the file based upon user input
	''''ENTER THE FileScriptingObject Code here
	''''Pass the path variable to this piece of the code
	''''Read the file into variable
 
	sSQL = Results of reading the TextFile
 
	'// Set the value
	oDataPump.SourceSQLStatement = sSQL
 
	'// Clean Up
	Set oDataPump = Nothing
	Set oPkg = Nothing
 
	Main = DTSTaskExecResult_Success
End Function
[+][-]03.25.2008 at 03:40PM PDT, ID: 21206999

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 06:05PM PDT, ID: 21207960

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.25.2008 at 07:06PM PDT, ID: 21208311

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL DTS, Visual Basic Programming, ActiveX
Tags: Microsoft, SQL Server, 2000, DTS
Sign Up Now!
Solution Provided By: SWRO
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628