Home Forums SQL Server 2005 T-SQL (SS2K5) Help with select statement when WHEN Clause involving multiple databases RE: Help with select statement when WHEN Clause involving multiple databases

  • you probably need to simply join three groups of data together to create your view; it might be slow;

    CREATE VIEW vwGeneralTransactionsMultiSite

    AS

    SELECT T1.Site,

    T1.Trans_num,

    T2.*

    FROM GeneralTransactions

    INNER JOIN Site1DB.dbo.GetDetails T2

    ON T1.trans_num = T2.trans_num

    AND T1.Site = 'Site1'

    UNION ALL

    SELECT T1.Site,

    T1.Trans_num,

    T2.*

    FROM GeneralTransactions

    INNER JOIN Site2DB.dbo.GetDetails T2

    ON T1.trans_num = T2.trans_num

    AND T1.Site = 'Site2'

    UNION ALL

    SELECT T1.Site,

    T1.Trans_num,

    T2.*

    FROM GeneralTransactions

    INNER JOIN Site3DB.dbo.GetDetails T2

    ON T1.trans_num = T2.trans_num

    AND T1.Site = 'Site3'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!