July 10, 2015 at 9:31 am
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.
July 10, 2015 at 9:50 am
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.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 10, 2015 at 9:56 am
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 ?
July 10, 2015 at 11:15 am
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)
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
July 10, 2015 at 11:17 am
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
Change is inevitable... Change for the better is not.
July 10, 2015 at 12:57 pm
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.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply