Running a Select query against multiple sql servers using SSIS script task.

Hi Guys,
I need to fetch data from multiple sql servers using  SSIS scirpt task inside a foreach container.
is there anyway i can build dynamic sql connections using ssis variables inside SSIS script task in each loop
Please guide me or refer any blogs so that i will try..
Thanks in advance.

Your only options is using .net code, then it will be no different than using a console app in a loop.
using (SqlConnection connection = new SqlConnection(connectionString))
connection.Open();
Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
Console.WriteLine("State: {0}", connection.State);
and so forth for each connection string
the connection string would come from the ForEach loop
Arthur My Blog

Similar Messages

  • Backup Status for Multiple SQl Servers.

    Hi All,
    What changes are required in the below script - so that it displays the backup result for
    multiple SQL SERVERS.
    --Databases with data backup over 24 hours old
    SELECT
       CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server,
       msdb.dbo.backupset.database_name,
       MAX(msdb.dbo.backupset.backup_finish_date) AS last_db_backup_date,
       DATEDIFF(hh, MAX(msdb.dbo.backupset.backup_finish_date), GETDATE()) AS [Backup Age (Hours)]
    FROM    msdb.dbo.backupset
    WHERE     msdb.dbo.backupset.type = 'D' 
    GROUP BY msdb.dbo.backupset.database_name
    HAVING      (MAX(msdb.dbo.backupset.backup_finish_date) < DATEADD(hh, - 24, GETDATE())) 
    UNION 
    --Databases without any backup history
    SELECT     
       CONVERT(CHAR(100), SERVERPROPERTY('Servername')) AS Server, 
       master.dbo.sysdatabases.NAME AS database_name, 
       NULL AS [Last Data Backup Date], 
       9999 AS [Backup Age (Hours)] 
    FROM
       master.dbo.sysdatabases LEFT JOIN msdb.dbo.backupset
           ON master.dbo.sysdatabases.name  = msdb.dbo.backupset.database_name
    WHERE msdb.dbo.backupset.database_name IS NULL AND master.dbo.sysdatabases.name <> 'tempdb'
    ORDER BY 
       msdb.dbo.backupset.database_name
    Thanks..!!

    Hi Prashanth,
    what location do I need to provide for SQL Server for link: http://blogs.technet.com/b/heyscriptingguy/archive/2011/05/02/use-powershell-to-report-sql-server-backup-status.aspx
    { $location = "SQLSERVER:\SQL\$SQLInstance\Databases" }
    else
    { $location = "SQLSERVER:\SQL\$SQLInstance\DEFAULT\Databases" }    ??

  • SELECT query from multiple databases

    Hi,
    Is it possible to run a SELECT query using multiple DBs' tables, like outer joining them. One of the DBs is Sybase.
    Thanks in advance

    A TopLink session can span multiple databases if they can be accessed through a single connection. A single select would require the database to handle the aggregation as mentioned in the other post.
    Alternatively TopLink's session broker will support making a single session present persistent types from multiple independent databases. This approach will not support a single SELECT spanning the databases though.
    Doug

  • Import HL7 data in sql server using ssis

    Could I know how to import HL7 data in sql server using ssis.
    I am not aware of any .NET code.
    Could someone provide me with any kind of custom code so I can try to understand and use it to my specifications.
    Thanks
    Latha

    As COZYROC said, HL7 is a type of EDI file. There is nothing built into SQL Server to handle this type of parsing.  You will either need to buy something or write your own, which I do not recommend because it is much more difficult than you imagine.
    You can use BizTalk to parse the data into an XML format which can then be processed by SQL Server.
    http://msdn.microsoft.com/en-us/library/bb981217(v=bts.10).aspx

  • Calculate the sum of values in excel file and import it to SQL table using SSIS

    Hi,
    Can some one help me how to do auto sum of columns in SQL table  using SSIS
    in SQL table the HRA , PF and Basic should not come, Only it should appear in basic pay as the sum of HRA , PF and Basic...

    RSingh, Thanks for the use
    of derived column.
    Instead of using record set i used  OLE DB destination
    its working Fine...
    but now the issue is if i put a new records in excel file its replicating in SQL table 
    How to get only the changed values in excel to SQL table.

  • Pure SQL of Select query on multiple tables in DB Adapter

    I am trying use pure sql approach for a custom sql query on multiple tables for a DB adapter by modifying toplink_mappings.xml. But i am not getting other tables in my xsd. Please help.

    hi Ravi,
    can you pls be a bit clear? what is this about? where you are using?
    thanks,
    sneha.

  • Select query inside PL/SQL block.

    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?)
    I know this is kind of very basic question, I tried searching this on the forum but could not find the thread, please redirect me to the link if this is already answered.

    user8578271 wrote:
    Hello Experts,
    I am just a beginner with PL/SQL.
    If I write a select query from client like SQL dev and fire it against a database, it gives me result.
    Eg: select * from employee;
    Now when I use the same Query inside a PL/SQL block suppose:
    Declare
    begin
    select * from employee;
    end;
    This gives error on execution, mentioning that an INTO is expected etc...
    I have doubts here:
    1. Can't I use a plain select inside a PL/SQL block (if so why?) Because when you run a query in a tool like SQL Developer, or SQL*Plus or TOAD etc. then it opens up a cursor and fetches the data into internal memory structures before displaying it, and that is all done automatically and hidden from you. In PL/SQL, there is no interface to display the results of SQL queries, so you have to specifically tell it what to put the data into.
    The syntax is (in basic terms)...
    SELECT column1, column2... columnX
    INTO variables or record structure
    FROM ...Though that can only select a single row of data. If your query returns more than 1 row it will give a TOO_MANY_ROWS exception. If your query returns no rows you will get a NO_DATA_FOUND exception.
    If you need to select multiple rows into variables etc., then you would need to "BULK COLLECT" into a collection/array structure, though this takes up valuable memory on the server and shouldn't be used unless necessary (and you understand the implications of doing it).

  • How to use one query against multiple table and recieve one report?

    I have duplicate tables, (except for their names of course) with commodities prices. They have the same column headings, but the data is different of course. I have a query that gives me a certain piece of information I am looking for but now I need to run this query against every table. I will do this every day as well, to see if the buying criteria is met. There are alot of tables though (256). Is there a way to say run query in all tables and return the results in one place? Thanks for your help.

    hey
    a. the all 256 tables whuld be one big partitoned table
    b. you can use all_tables in order to write a select that will write the report for you:
    SQL> set head off
    SQL> select 'select * from (' from dual
      2  union all
      3  select 'select count(*) from ' || table_name || ' union all ' from a
      4  where table_name like 'DB%' AND ROWNUM <= 3
      5  union all
      6  select ')' from dual;
    select * from (
    select count(*) from DBMS_LOCK_ALLOCATED union all
    select count(*) from DBMS_ALERT_INFO union all
    select count(*) from DBMS_UPG_LOG$ union all
    remove the last 'union all', and tun the generated quary -
    SQL> set head on
    SQL> select * from (
      2  select count(*) from DBMS_LOCK_ALLOCATED union all
      3  select count(*) from DBMS_ALERT_INFO union all
      4  select count(*) from DBMS_UPG_LOG$
      5  );
      COUNT(*)
             0
             0
             0
    Amiel

  • Cisco ACS 5.2 authentication against multiple LDAP servers

    Hi Folks,
    I have a wireless network that uses ACS 5.2 to handle authentication.   The ACS is integrated with an Active Directory LDAP server (my_ldap) and is working correctly at the moment.    The authentication flow looks like this:
     - User tries to associate to WLAN
     - Authentication request is sent to ACS
     - Service selection rule chooses an access-policy (wireless_access_policy)
     - wireless_access_policy is configured to use my_ldap as identity source.
    A sister company is about to move into our offices, and will need access to the same WLAN.    Users in the sister company are members of a separate AD domain (sister_company_ldap).    I would like to modify the wireless_access_policy so that when it receives an authentication request it will query both my_ldap and sister_company_ldap, and return a passed authentication if either attempt is successful.     Is this possible?

    Assuming you're already authenticating using your AD binding and AD1 as your identity source, you can add a further LDAP server as another identity source and add this to your identity store sequence in your access policy to authenticate against both.
    You can also add multiple LDAP servers and add them both to the identity store sequence (if you're not using AD1).

  • Unable to set count for Select Query for BizTalk SQL receive port

    Hi All,
    Iam using BizTalk server 2009 classic SLQ adapter (using XML clause)for my integration to pull records from DB in to my application.
    As per the DB values iam unable to set the record count as this started giving me error below (first it worked for 820 records with select Query.and then 400 and going down with respect to multiple runs).Kindly help .
    Thanks in advance.

    Hi Abhishek,
    iam still getting the same error for 1000 records.
    after turning off PreserveBOM aswell in send pipeline.
    There was a failure executing the receive pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "Pipeline " Receive Port:
    "SQLPort" URI: "SQL://XXXXX/OneC_DB/" Reason: An error occurred when parsing the incoming document: "'
    ', hexadecimal value 0x0B, is an invalid character. Line 188, position 3944.". 

  • Multiple values in where clause(IN) of select query in Cisco Cloud Portal using single field

    I can actually pass multiple values in the IN statement of select query using multiple dictionary fields in the data retrieval rule of the AFC in Cisco cloud portal like
    #dictionary.field1# = 1 and
    #dictionary.field2#=2
    select col1,col2 from table1 where col3 in (#dictionary.field1#,dictionary.field2#).
    but I want to pass mutiple values in a single field as
    #dictionary.field1#=1,2
    select col1,col2 from table1 where col3 in (#dictionary.field1#) and the query gives no data because it is taking as '1,2' instead of '1','2'.
    Please give the solution for passing multiple values in a single variable to use in IN operator of WHERE clause

    Ok, I now understand what you are trying to do. Unfortunately, you cannot inject parts of a SQL statement into a DDR through a dictionary field, which always represents a specific value (the comma in your case is attempting injection of a SQL construct to refer to multiple values). One possible solution is to arbitrarily consolidate your list of values using a delimiter that you know will not be in the values themselves such as a colon (:). Let's use 3 values as it serves as a better example.
    Set your dictionary field to a single reference to all 3 values of interest, say 'a', 'b', 'c' as:
    :a:b:c:  (you can use javascript to create this consolidated dictionary field)
    Now your query would look something like the following:
    select col1,col2 from table1 where #dictionary.field1t# like '%:'+col3+':%'
    This should achieve the desired result.

  • How to Run a Select Query  stored in a Variable

    Hello,
    I have a following requirement:
    Result of one select query on Var1 , result of other select query in Var2 ,
    if Va2 = 'value11' OR Var2 = 'Value2' then Var1 = 'select query'. Now how can I run this SQL query at the end of the Pl/SQL?
    so I'm writing following query for the same:
    DECLARE
    qry nvarchar2(500);
    result nvarchar2(500);
    BEGIN
    select 'select TEXTVAL as "CHARG" FROM TABLE1 WHERE LOC =''[ParameterValue]'' and KEYNAME =''<<REPLACE>>''' INTO qry from dual;
    SELECT CASE WHEN count(RW."CountofBATCH") > 1 then 'Mixing'
    WHEN count(RW."CountofMAT") = 0 then 'None'
    ELSE 'Other'
    END
    INTO result
    FROM TABLENAME2 TT, XMLTable('/Rowsets/Rowset/Row' PASSING TT.XMLCOL
    COLUMNS
    "CountofBATCH" PATH '/Row[CLABS > 0]/CHARG',
    "CountofMAT" PATH '/Row[MATNR = "[Parameter Value]"]/MAT'
    ) AS RW
    where
    TT.PL = '[Parameter Value]' and
    TT.TANK = '[Parametr Value]' ;
    IF result = 'Mixing' OR result = 'None' THEN
    qry := replace( qry , '<<REPLACE>> ' , result);
    else
    qry := 'Nothing';
    END IF;
    This way the variable qry will have select statement. Now How can I run this qry variable to get the output of that select statement in the same query?

    you can use execute immediate if the output of the query is in the single query.
    that is very simple.
    have the query in the signle string and then pass like this
    declare
    qry varchar2(255);
    result varcharf2(2500);
    vempid number :=1;
    begin
    qry:='select empname from emp where empid=:empid';
    execute immediate qry into result using vempid;
    -----now the data result is in result
    end;

  • Running the same query against numerous databases

    My organization has 20+ clients. Each client has a separate database in the same MSSQL server*. For these purposes, the databases are structurally identical. I've been tasked to gather information from tables in all of these databases. I can use the same query on multiple clients - my issue is switching between databases.
    The naive solution would be for me to declare 20+ DataSource instances, and have some mapping from client name to DataSource. I think that's going to be a real mess and my inclination is to avoid it.
    Another possibility would be dynamically generating the PreparedStatement based on the client, something like
    "SELECT foo, bar " + "FROM " + client.getDatabaseName() + ".dbo.my_table";
    My understanding, though, is that it's a bad practice to have dynamically generated prepared statement calls and not possible to parameterize the 'from' clause.
    Another thing I've been digging around at is using a transaction and an SQL Server call to alter what database calls from that transaction go to. I thought that could be done, but I'm not finding anything which suggests it's possible.
    I guess I've identified my problem, but I'm thrashing on how to solve it. I'm still newish to non-trivial database interactions, so I'd appreciate any input. If I posted this in the wrong place, please feel free to yell at me and move it.
    Thanks in advance,
    Eric
    * Not my fault. I'm new.

    I'm collection usage and storage metrics. "Client X has 200 records, Client Y has 250. Client X has 15 active users, Client Y has 12."
    The data is being read from the client databases and stored into a separate metrics database.
    I anticipate it will be mostly select count() calls.
    I can. For the maintenance reasons I mentioned above, I'd rather not have to maintain all those datasources if I don't have to.
    No, the invocations will be sequential.
    for (each metric type) {
        for (each client) {
            gather information;
            add to batch
        update batch in metrics database
    }I guess I was hoping there was a Sekrit SQL way to swap what database inside a server instance the connection was pointing to. I'm guessing that's not going to happen, and I'm left with N datasources for N clients or generated preparedStatements which swap out the database name in the FROM portion.
    The data is being written to a table in a single, separate metrics database.
    I'm trying not to, honest.
    Edited by: 919852 on Mar 12, 2012 8:38 AM

  • How to run batch select query ?

    I have multiple "select" query .
    how do i run the query in a efficient way and absorp the values into an ArrayList ?
    addbatch() method is mainly used for "insert" kind of query .
    and also , it would be bad idea to run "select:" query one by one .
    can you tell whats the best use ?

    Are your queries related to each other, I mean, do you have something like
    select xpto from someTable where someValue = 1
    select xpto from someTable where someValue = 2
    select xpto from someTable where someValue = 3
    If it's something like this you can group
    select xpto from someTable where someValue in(1,2,3)
    If it is not I think there's no other way but running one at a time.
    mleiria

  • Querying against multiple subject areas

    We would like to write a query against two or more subject areas. Is that possible in OBI EE 10g? Looks like this is a feature available in Business Objects and our users are requesting it. Please suggest how it can be done.

    Hi Nico,
    You are correct, OBIEE 10g will let you use UNION statements in the complex SQL. In fact you can use "Combine with Similar Request" to drive a UNION, UNION ALL and MINUS statement from the Criteria tab without having to go to advanced settings.
    What we were trying to say above was that it doesn't let you JOIN two subject areas together. For example,
    SELECT SUBJECT_AREA1.COLUMN1, SUBJECT_AREA2.COLUMN2
    FROM SUBJECT_AREA1, SUBJECT_AREA2
    WHERE SUBJECT_AREA1.KEY = SUBJECT_AREA2.KEY
    The above just isn't possible.
    One thing you can do that sort of accomplishes it (but it behaves really kludgey) is use the union statement + null/0 place holders + group by statement. This is a pain though. For example:
    1) Your Logical SQL should be something like:
    SELECT SUBJECT_AREA1.COMMON_DIMENSION, SUBJECT_AREA1.MEASURE1, 0 MEASURE2
    FROM SUBJECT_AREA1
    UNION
    SELECT SUBJECT_AREA2.COMMON_DIMENSION, 0 MEASURE1, SUBJECT_AREA2.MEASURE2
    FROM SUBJECT_AREA2
    2) In the criteria tab, create new aggregate columns based on MEASURE1 and MEASURE2 grouped by COMMON_DIMENSION. For example:
    NEW_MEASURE1= SUM(MEASURE1 by COMMON_DIMENSION)
    NEW_MEASURE2=SUM(MEASURE2 by COMMON_DIMENSION)
    ***I think you have to reference the saw name and not the logical name at this point. Hence it may read something like: SUM(saw1 by saw0) and SUM(saw2 by saw0)
    3) Throw the COMMON_DIMENSION, NEW_MEASURE1, NEW_MEASURE2 into a pivot table and you're all set.
    Like I mentioned, it behaves very strangely and is a pain to implement, but it does display the expected results a join would.
    -Joe

Maybe you are looking for

  • Can I use a g5 as a server?

    Have a G5, dual 2GHz, with 2.5 GB RAM. Currently running a Mini, iPad 3rd gen & 2 iPhones (both 4S). Am considering using G5 as a server. Is it doable, and if so, how? (Also have an old blue & white G3, if that can be useful.) Right now, the G5 is al

  • Message Mapping - IDOC to http

    Hi , I am creating Message mapping for IDOC to Http scenario. In which i have the following requirement. For a partner Role in segment E1BPDLVPARTNER we need to get the Address_No value and then with that we need to get the address from segment E1BPA

  • Php localhost vs 127.0.0.1 vs file:/// behave differently

    I set up php to do web development on my MBP 10.5.8 following this guide http://foundationphp.com/tutorials/php_leopard.php and things are working... sort of. The issue I'm having is that when I load pages in Safari using localhost, 127.0.0.1, and di

  • ABAP Add-On Installation issue

    Hi Experts, We are trying to Install our package by using Add On Installation Tool-SAINT but our package is not listed on Installable Add On packages list but to continue Installation we need to have our package on the list. The steps we carried out

  • Rest API search by updatedAt?

    Hi, I've been trying to do a search by updatedAt through the REST API.  I haven't been able to get it to work.  Is it possible to do this search? I've tried using epoch time, and I've tried using the date formats mm/dd/yyyy and yyyy/mm/dd.  Maybe I j