Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

TSQL Scenario

You have a table named Providers, which has two fields, ProviderCode and ProviderName.  You have a second table called Accounting with two fields AccountProviderCode and AccountPatientCode.  Write a single TSQL statement to generate a third table called Merged, combining the ProviderName from the Providers table with all the records and fields from the Accounting table.
Avatar of eddyevations
eddyevations

insert into Merged
         select
            A.ProviderName as ProviderName , B.*      
      from
            Providers A
      cross join
            Accounting B
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
if, on the other hand, you know that there is exactly one AccountProviderCode for each ProviderCode, then the simplest query would be this:

INSERT INTO Merged
 SELECT ProviderName, AccountProviderCode, AccountPatientCode
 FROM Providers, Accounting WHERE ProviderCode = AccountProviderCode