locked
loading data error RRS feed

  • Question

  • User-7838209 posted

    hi all

    i need to retrive data from database from 2 tables in 2 different databases on same server using the user id as a key

    is it possible??

    Tuesday, May 14, 2013 2:25 AM

Answers

  • User-1800438376 posted

    they are tables in different database with 2 different connection string on same server

    If its on same server then you can do something like this.

    create procedure sp1(@strUserId varchar(10))
    
    as begin
    
    select * from db1.dbo.tblUser where userid IN (select userid from db2.dbo.tblUser where userid = @strUserId)
    
    end
    
    go
    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2013 5:31 AM
  • User-7838209 posted

    thanks alot it worked

    select distinct a.EMPNBR, a.EMPNAM ,b.CLINTYP,b.VSTDTE from MAINFRAME.EMPBAS a inner join CLINIC.CLNCVST b ON a.EMPNBR=b.EMPNBR where b.EMPNBR IN (select EMPNBR from CLINIC.CLNCVST where VSTDTE='" + DropDownList1.SelectedValue + "')and VSTDTE= '" + DropDownList1.SelectedValue + "'")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2013 7:31 AM

All replies

  • User-1800438376 posted

    yes it is possible create 2 different connection to fetch the data based on the user id, provide both table exists in both the database.

    Note: you need to have access to connect different database.

    Tuesday, May 14, 2013 4:32 AM
  • User-7838209 posted

    they are tables in different database with 2 different connection string on same server

    Tuesday, May 14, 2013 5:07 AM
  • User-1800438376 posted

    they are tables in different database with 2 different connection string on same server

    If its on same server then you can do something like this.

    create procedure sp1(@strUserId varchar(10))
    
    as begin
    
    select * from db1.dbo.tblUser where userid IN (select userid from db2.dbo.tblUser where userid = @strUserId)
    
    end
    
    go
    
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2013 5:31 AM
  • User-1716253493 posted

    they are tables in different database with 2 different connection string on same server

    try use stored proc

    Tuesday, May 14, 2013 6:13 AM
  • User-7838209 posted

    thanks alot it worked

    select distinct a.EMPNBR, a.EMPNAM ,b.CLINTYP,b.VSTDTE from MAINFRAME.EMPBAS a inner join CLINIC.CLNCVST b ON a.EMPNBR=b.EMPNBR where b.EMPNBR IN (select EMPNBR from CLINIC.CLNCVST where VSTDTE='" + DropDownList1.SelectedValue + "')and VSTDTE= '" + DropDownList1.SelectedValue + "'")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 14, 2013 7:31 AM