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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Displaying a Global Variable in Query Results

Author  Topic 

SimonP
Starting Member

4 Posts

Posted - 2004-08-06 : 12:37:26
I've developed a DTS package and am using a global variable to limit which records get affected by an Execute SQL Task.

The variable is defined at the package level and I am able to reference it in the WHERE clause of my query by setting it as a parameter (using ?) and mapping the global variable to the parameter.

What I can't do is get the global variable to show up in the results of my query. Can someone tell me how to make reference to the global variable outside of the WHERE clause? For example:

Insert into tablename1 (field1, field2)
select tablename2.RecordID, ?
from tablename2
where tablename2.country = ?

The ? works for the where clause but not for the select clause.

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-08-06 : 13:45:59
I'd use:
Insert into tablename1 (field1, field2)
select tablename2.RecordID, tablename2.country
from tablename2
where tablename2.country = ?
-PatP
Go to Top of Page

SimonP
Starting Member

4 Posts

Posted - 2004-08-09 : 04:20:08
Thanks Pat. That works for one query I have. But now I have a query where the field value I want to insert does not exist in my original table. So now the SQL statement would be:

Insert into tablename1 (field1, field2)
select tablename2.RecordID, ?
from tablename2
where tablename2.country <> ?

Any ideas on how I can get this to work?

Go to Top of Page

Pat Phelan
Posting Yak Master

187 Posts

Posted - 2004-08-09 : 12:03:13
Switch from a query to a stored procedure.

-PatP
Go to Top of Page
   

- Advertisement -