Not able get output because problem with link server

  • hi Sql folks,

    i am using open query in ms sql 2012 to access some data from my sql using tables and joinings.

    in the query , i am using some variables. like

    set @row_no=-1;

    set @systm='text';

    sql query using joinings.

    because of above variables , i am not able execute the query.

    can any one tell why i am not able executing the query using open query from mssql?

    but i am successfull running the query in my sql .

    please ask me about any additional information.

  • raghava_tg (7/10/2015)


    hi Sql folks,

    i am using open query in ms sql 2012 to access some data from my sql using tables and joinings.

    in the query , i am using some variables. like

    set @row_no=-1;

    set @systm='text';

    sql query using joinings.

    because of above variables , i am not able execute the query.

    can any one tell why i am not able executing the query using open query from mssql?

    but i am successfull running the query in my sql .

    please ask me about any additional information.

    Okay, how about posting the actual query? We have zero information on what you mean when you say you are "not able execute the query". Does an error message appear? Did a resultset get generated, even if it had 0 records in it? Just knowing you used OPENQUERY doesn't really tell us anything that we can use to help you. After all, we can't see your screen, or know anything whatsoever about what your query is supposed to do, or even why you need those variables, as you haven't given us those details. Please be specific and spell out exactly what you have for a query, exactly what it is supposed to do, and what the variables are there for, and as much other info as you have.

  • i can't post the query , because of restrictions in my Company.

    will post sample tables data and query i am using.

    in the mean while can any one directing me any good article regarding open query ?

  • raghava_tg (7/10/2015)


    i can't post the query , because of restrictions in my Company.

    will post sample tables data and query i am using.

    in the mean while can any one directing me any good article regarding open query ?

    Have you at least looked at what is in Books Online (aka BOL)? It's the help within SQL Server Management Studio (aka SSMS)

  • raghava_tg (7/10/2015)


    i can't post the query , because of restrictions in my Company.

    will post sample tables data and query i am using.

    in the mean while can any one directing me any good article regarding open query ?

    You'll need to use dynamic SQL to build the open query command and then execute the dynamic SQL.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
    "Change is inevitable... change for the better is not".

    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)
    Intro to Tally Tables and Functions

  • Jeff Moden (7/10/2015)


    raghava_tg (7/10/2015)


    i can't post the query , because of restrictions in my Company.

    will post sample tables data and query i am using.

    in the mean while can any one directing me any good article regarding open query ?

    You'll need to use dynamic SQL to build the open query command and then execute the dynamic SQL.

    The reason for this is that variables you declare outside that query are not valid or known about in the execution of it. They exist only in the batch to the point of it being at least possible to append them in some fashion to the query string sent to OPENQUERY, and in the apprpriate portion of that query. In other words, variables that you declare in your batch prior to the use of OPENQUERY, don't exist inside the execution of what you are sending to the other server.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply