Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rmazzol
Starting Member
1 Post |
Posted - 2005-02-01 : 14:08:57
|
Hi,I am creating a package in which I have 2 global variables. I want to be able to access those global variables through an Execute SQL Task. The values of my variables come from a .ini file. At the moment, I insert the value of the variables into a temp table through one SQL task using parameters, and then through another I assign them to two variables declared within that task so that I can use them. I would like to avoid having to do it this way, but at the same time, not have to use an ActiveX script, if possible. Without using the first SQL task to insert the variables into a temp table, I get the following error:Error Source: Microsoft OLE DB Provider for SQL ServerError Description: Syntax error or access violation.Am I getting this b/c you are not allowed to access global variables via an SQL task?Here is an example of what I'm doing:First SQL task:INSERT INTO DTSParam (DTSName, ParamName, ParamVal)VALUES ('NameOfDTS', 'NameofParam1', ?)Then I set up the Parameter 1 for the ?. I have 2 of these, one for each of the 2 global variables.Second SQL task:DECLARE @DateUnit datetime --date value storedDECLARE @MonthCount int --#added to months valueDECLARE @StartDate datetime --starting allocation dateDECLARE @MonthsOut int --#of months to allocate--Set to 0 so that it starts with value of StartDateSET @MonthCount = 0--Set to the value inputted in the ini file that was added to the DTSParam tableSET @MonthsOut = (SELECT TOP 1 ParamValue FROM DTSParam WHERE DTSName = 'NameOfDTS' AND ParamName = 'NameOfParam1')--Set to the value inputted in the ini file that was added to the DTSParam tableSET @StartDate = (SELECT TOP 1 ParamValue FROM DTSParam DTSName = 'NameOfDTS' AND ParamName = 'NameOfParam2')WHILE @MonthCount < @MonthsOutBEGINSET @DateUnit = DATEADD(mm, @MonthCount, @StartDate ) INSERT INTO Table1 (ID, Date, Value, TimeStamp)SELECT sa.ID, @DateUnit, t2.Val, getDate()FROM Table3 t3 INNER JOIN Table2 t2ON t3.ID = t2.IDAND t3.EmpD = t2.EmpIDSET @MonthCount = @MonthCount + 1ENDSo, essentially, instead of setting @StartDate and @MonthsOut to a Select statement, I'd like to set them to the global variable directly... with a ? or something else... if possible.Is it? Thanks. |
|
|
|
|
|
|
|