locked
1 Query, 2 Databases RRS feed

  • Question

  • User-2051275383 posted

    Hey guys,

    I am trying to query 2 seperate databases in the one query.. I am hoping you can help me out, here is my code:

     var bb_db = Database.Open("BBLEARN");
     var local_db = Database.Open("dev");
    
     var generate_staff_list = Query(@"SELECT local_db.t1.[staff_id] as StaffId, local_db.t1.[student_id] As StudentId, bb_db.t2.[pk1] AS CasesStaff, bb_db.t3.[pk1] AS CasesStudent, FROM local_db.import AS t1 INNER JOIN bb_db.users AS t2 ON t1.StaffId = t2.pk1 INNER JOIN bb_db.users AS t3 ON t1.StudentId = t2.pk1");

    I know that the syntax isn't correct but if someone can point me in the right direction, I would be appreciative!


    Regards, Aaron
     

    Monday, May 27, 2013 12:35 AM

All replies

  • User1088758208 posted

    You can use query like this

    SELECT firstdb.*, seconddb.* FROM Server1.Database1.dbo.myTable AS firstdb INNER JOIN Server2.Database2.dbo.myTable AS seconddb ON firstdb.id = seconddb.id

    Monday, May 27, 2013 12:46 AM
  • User-2051275383 posted

    I get this error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

    Compiler Error Message: CS1061: 'char' does not contain a definition for 'CasesStudent' and no extension method 'CasesStudent' accepting a first argument of type 'char' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 29: <td>row.CasesStaff</td>
    Line 30:  
    Line 31: <td>@row.CasesStudent</td> Line 32: 
    Line 33: }


    Source File: e:\Skydrive\Web & Application Development\WebMatrix Projects\Mini Apps\Default.cshtml    Line: 31

    Monday, May 27, 2013 1:29 AM
  • User895691971 posted

    I get this error:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

    Compiler Error Message: CS1061: 'char' does not contain a definition for 'CasesStudent' and no extension method 'CasesStudent' accepting a first argument of type 'char' could be found (are you missing a using directive or an assembly reference?)

    Source Error:

    Line 29: <td>row.CasesStaff</td>
    Line 30:  
    Line 31: <td>@row.CasesStudent</td> Line 32: 
    Line 33: }


    Source File: e:\Skydrive\Web & Application Development\WebMatrix Projects\Mini Apps\Default.cshtml    Line: 31

    This error is due to unsame data types. Or error in showing the data!

    You can check, that whether your database contain the same naem of table and the column. If yes, then there is error in 

    SELECT * FROM table WHERE this = this;

    Or the error will be in 

    foreach (var this in that) {
    
    }

    Check these, there is no other error!

    Monday, May 27, 2013 10:28 AM
  • User-2051275383 posted

    I am still having no luck with this. The 2 tables don't have any columns called the same thing?

    Any help is appreciated with this matter.

    Regards, Aaron 

    Monday, May 27, 2013 6:44 PM
  • User895691971 posted

    There will be two columns in these two tabels, which are matching like Uploader_ID and User_ID. Try to extract values from that!

    Friday, May 31, 2013 5:07 AM
  • User895691971 posted

    There will be two columns in these two tabels, which are matching like Uploader_ID and User_ID. Try to extract values from that!

    Friday, May 31, 2013 5:07 AM
  • User-1181481928 posted

    dear my advice to you is create string value that's have the query , and then you can used to your sperate databases

    regards.

    Sunday, June 2, 2013 6:48 AM
  • User-2051275383 posted

    I require further help with this.. I am unsure how to write the query..

    Compiler Error Message: CS0103: The name 'Query' does not exist in the current context 

    Monday, June 17, 2013 6:56 PM
  • User895691971 posted

    Sorry for late reply!

    This error means that there is no variable named Query in your code, or you are using IF..ELSE block around it.

    Tuesday, June 25, 2013 5:10 AM