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 5956043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:12:00+00:00 2026-05-22T18:12:00+00:00

I have 2 dbs one on MS SQL and another on Mysql. I have

  • 0

I have 2 dbs one on MS SQL and another on Mysql. I have written some sql scriots which fetch data from Mysql and insert into MS SQL. To do this I have set up device driver connection and linked server on MS SQL and these scripts are executed on MS SQL. Scripts are simple and have only select statements.
Now I need to write dynamic scripts to fetch data from mysql based on some parameters. Below is sample query to get data from DB “stagedb_ie” where ie stands for Ireland.

select * from openquery(stagedb_ie, 'select * from stagedb_ie.aol_center')

There are other dbs in mysql with country code suffix to stagedb as name. Now I want to pass this country code as parameter to query and get data. e.g.

declare @stagedb_country varchar(20)
set @stagedb_country = 'stagedb_ie'
select * from openquery(@stagedb_country, 'select * from '+ @stagedb_country +'.aol_center')

But this query doesn’t work. any suggestion?

  • 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-05-22T18:12:01+00:00Added an answer on May 22, 2026 at 6:12 pm
    declare @stagedb_country varchar(20),
       @SQL nvarchar(max);
    set @stagedb_country = 'stagedb_ie';
    set @SQL = 'select * from openquery(' + @stagedb_country
       + ', ''select * from ' + @stagedb_country + '.aol_center'')';
    exec (@SQL);
    

    Be aware that dynamic SQL in SPs executes with the permissions of the caller not the SP owner.

    Last, I question why you’re using separate databases and tables for this. Can you not encode what you need in the data instead of putting the data in different containers?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Webapp which connects to 2 DBs (one core, the other is
I have a web-app that has a master mysql db and four slave dbs.
I have a couple of databases containing simple data which needs to be imported
I have an application that (currently) needs to uses DBs served by both SQL
My app consolidates data from other DBs for reporting purposes. We can't link the
I have a HTTP sever in one program and my basic application in another
We have an Access database migrated from Access 97 to Acces 2007 with some
Im creating an IPad Application which will have an SQL Server backend. My question
I am running 2 mysql dbs. one on linux (v5.0.x) and one on windows
I have a SQL query of the form SELECT ... FROM A@DB1 a, B@DB1

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.