I have to retrive the data from one service based sql server to another service based sql server
select * from servernameA.db_name.dbo.table_name
where column in (select column from servernameb.db_name.dbo.table_name)
I have to retrive the data from one service based sql server to another service based sql server
select * from servernameA.db_name.dbo.table_name
where column in (select column from servernameb.db_name.dbo.table_name)
So what's the problem? You can do it.
Just a little performance improvement in your query with DISTINCT
.
select * from servernameA.db_name.dbo.table_name
where column in (select DISTINCT column from servernameb.db_name.dbo.table_name)
For your reference:
Query across multiple databases on same server
Selecting data from two different servers in SQL Server
------------Edit----------------
How about this? I haven't tried this yet. Give this a try.
// connectionString is the connection string for the ServerA..DB1
using (var conn = new SqlConnection(connectionString))
{
conn.Open();
// provide commandText as the SQL query having the full name of Server2..DB2
using (var command = new SqlCommand(commandText, conn))
{
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// read the result
}
}
}
}