Showing posts with label openquery. Show all posts
Showing posts with label openquery. Show all posts

Thursday, March 22, 2012

asp page variable to sql to openquery

Im having trouble putting all of this together, but here is the
scenario
ASP page with a Query String Variable,
Example: http://mywebsite/mywebpage.aspx?variable=x
now i need to query using openquery across a linked server using this
variable.
Like:
SELECT COLUMN1, COLUMN2
FROM OPENQUERY(LINKEDSERVER, '
SELECT COLUMN1, COLUMN2
FROM LINKEDSERVERTABLE
WHERE COLUMN3=@.VARIABLE')
I know this won't work, but this is the concept, if i run the query
against the linked server then my results take about 20 seconds to
return, but if i could pass the variable to an openquery then my
results would be returned in 1-2 seconds. which is acceptable. Thanks
for any help in advance!!You need to build the SQL statement as a string and
then pass that string to an EXEC. You can find more
information and an example in the following article:
HOW TO: Pass a Variable to a Linked Server Query
http://support.microsoft.com/?id=314520
-Sue
On 3 Aug 2006 16:07:15 -0700, joshd@.norrisinc.com wrote:

>Im having trouble putting all of this together, but here is the
>scenario
>ASP page with a Query String Variable,
>Example: http://mywebsite/mywebpage.aspx?variable=x
>now i need to query using openquery across a linked server using this
>variable.
>Like:
> SELECT COLUMN1, COLUMN2
> FROM OPENQUERY(LINKEDSERVER, '
> SELECT COLUMN1, COLUMN2
> FROM LINKEDSERVERTABLE
> WHERE COLUMN3=@.VARIABLE')
>I know this won't work, but this is the concept, if i run the query
>against the linked server then my results take about 20 seconds to
>return, but if i could pass the variable to an openquery then my
>results would be returned in 1-2 seconds. which is acceptable. Thanks
>for any help in advance!!