Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9164799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:46:02+00:00 2026-06-17T14:46:02+00:00

One strange attribute of T-SQL’s OPENROWSET() function is that it cannot accept parameters within

  • 0

One strange attribute of T-SQL’s OPENROWSET() function is that it cannot accept parameters within the ‘query’ which it executes remotely. In order to get around this I guess you have to create a long string containing the OPENROWSET calls and the parametrized query.

Given this limitation, I’m trying to get this piece of code to work:

Declare @DataId int
Declare @RecordType varchar(50)
Declare @Filter varchar(50)

 -- ...

SELECT TOP 1 
    @RecordType = recordType,
    @DataId = DataId
FROM OPENROWSET('SQLNCLI', 
                'Server=MyServer;Trusted_Connection=yes;',
                'SELECT recordType, DataId FROM MyDb..data_lookup
                 WHERE Filter = ''' + @Filter+'''')

This throws an error

Incorrect syntax near ‘+’

Right now, which makes sense given the restriction on OPENROWSET. But if I convert this to SQL string, won’t I lose the ability to set @RecordType and @DataId from the results of the query?

Is there any syntactic sugar I can sprinkle on this to get around the restriction and make this work the way I want it to?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T14:46:03+00:00Added an answer on June 17, 2026 at 2:46 pm

    Here’s some examples of building a string dynamically:

    http://support.microsoft.com/kb/314520

    You could insert into a table variable first, and then pull your values from there.

    DECLARE @t TABLE (DataID int, RecordType varchar(50))
    INSERT INTO @t
    exec sp_executeSQL N'your OPENROWSERT query'
    
    SELECT TOP 1 @DataID = DataID, @RecordType = RecordType
    FROM @t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Strange one this, which isn't programming related directly, but I thought it important to
I have a strange one. Create a new form. Then add the following function
This is a strange issue - one that I've never noticed before. A verification
I promise you I am not lying. There is one strange line in this
Strange one. Trying to calculate the Chinese zodiac year in MySQL. The years such
Here's a strange one. After renaming a class, one of my forms began giving
I'm having facing problemind with LDAP, its bit strange one. My Web server is
Is connecting with one IP but an error occurs with a complete strange host/ip??
This is a really strange issue. One day my project started to do a
I just see strange behaviour in Eclipse . I am developing one android project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.