Query to get data from two tables and return them togetherHow to return only the Date from a SQL Server DateTime datatypeGet list of databases from SQL ServerHow do I get list of all tables in a database using TSQL?SQL update from one Table to another based on a ID matchHow can I get column names from a table in SQL Server?Selecting data from two different servers in SQL Serversql query to return differences between two tablesGet all table names of a particular database by SQL query?How to remove a column from an existing table?Get size of all tables in database

Motorcyle Chain needs to be cleaned every time you lube it?

Declining a date invitation from a friend while minimizing the hurt feelings?

Should I warn my boss I might take sick leave?

Do intermediate subdomains need to exist?

Advice for making/keeping shredded chicken moist?

Will Jimmy fall off his platform?

Who is responsible for exterminating cockroaches in house - tenant or landlord?

Isn't "Dave's protocol" good if only the database, and not the code, is leaked?

Taking advantage when the HR forgets to communicate the rules

What is the shape of the upper boundary of water hitting a screen?

How serious is plagiarism in a master’s thesis?

What are some bad ways to subvert tropes?

How can a ban from entering the US be lifted?

What can a novel do that film and TV cannot?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Should I increase my 401(k) contributions, or increase my mortgage payments

What is it called when the tritone is added to a minor scale?

Can a USB hub be used to access a drive from 2 devices?

Curve fitting when data has a sharp initial slope and then tapers off

What's the difference between a type and a kind?

What's the big deal about the Nazgûl losing their horses?

Why no parachutes in the Orion AA2 abort test?

Why would "dead languages" be the only languages that spells could be written in?

Taking my Ph.D. advisor out for dinner after graduation



Query to get data from two tables and return them together


How to return only the Date from a SQL Server DateTime datatypeGet list of databases from SQL ServerHow do I get list of all tables in a database using TSQL?SQL update from one Table to another based on a ID matchHow can I get column names from a table in SQL Server?Selecting data from two different servers in SQL Serversql query to return differences between two tablesGet all table names of a particular database by SQL query?How to remove a column from an existing table?Get size of all tables in database






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I have a quick question in regards to using sql-server.
I have two tables, one for insurers, and another for appointments. My goal is to create a query where I grab all the appointments that use two specific insurers. For example, I want all the assignments that use state farm and USAA as their insurer.



SELECT TOP (1000) [Id]
,[Name]
,[AddressOne]
,[AddressTwo]
,[City]
,[State]
,[Zip]
,[PrimaryPhone]
,[SecondaryPhone]
,[Fax]
,[InsurerStatusId]
,[InsuranceGroupId]
,[ModifiedDate]
,[ModifiedBy]
,[ReportInsuranceName]
,[ReportInsuranceId]
FROM [AssignmentManagement].[dbo].[Insurers]

SELECT TOP (1000) [Id]
,[AppointmentTypeId]
,[AssignmentId]
,[StaffId]
,[CalendarId]
,[AppointmentDate]
,[ScheduledDate]
,[RequestedAppointmentDate]
,[Notes]
,[Hour]
,[Minute]
,[DayOfTheWeek]
,[CenterId]
,[AppointmentStatusId]
,[RentalCar]
,[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Appointments]

SELECT TOP (1000) [Id]
,[InsurerId]
,[RepairCategoryId]
,[AssignmentStatusId]
,[OriginalCenterId]
,[OriginalStaffId]
,[LossCategoryId]
,[ClaimNumber]
,[PolicyNumber]
,[LossDate]
,[TotalLossIndicator]
,[Source]
,[PrimaryCustomerType]
,[InsuredCustomerId]
,[OwnerCustomerId]
,[ClaimCustomerId]
,[CustomerServiceRepresentativeId]
,[TransactionId]
,[Towing]
,[RentalCar]
,[IsDriveIn]
,[Deductible]
,[DeductibleStatus]
,[PhotosOnly]
,[LeftMessageSequence]
,[VehicleYear]
,[VehicleMake]
,[VehicleMakeDescription]
,[VehicleModel]
,[VehicleColor]
,[VIN]
,[Odometer]
,[LicenseNumber]
,[LicenseState]
,[VehicleLocationName]
,[VehicleAddressOne]
,[VehicleAddressTwo]
,[VehicleCity]
,[VehicleState]
,[VehicleZip]
,[VehiclePhone1]
,[VehiclePhone1Ext]
,[VehiclePhone2]
,[VehiclePhone2Ext]
,[VehicleContactFirstName]
,[VehicleContactLastName]
,[VehicleCondition]
,[VehicleNotes]
,[Impact1]
,[Impact2]
,[ClaimOfficeName]
,[AgentName]
,[AgentFirstName]
,[AgentLastName]
,[AgentAddressOne]
,[AgentAddressTwo]
,[AgentCity]
,[AgentState]
,[AgentZip]
,[AgentLicenseNumber]
,[AgentPhone]
,[AgentPhoneExt]
,[AgentFax]
,[AgentEmail]
,[PriorDamage]
,[Notes]
,[DamageNotes]
,[SpecialInstructions]
,[DispatchNotes]
,[LossNotes]
,[OtherNotes]
,[AssignmentDate]
,[ReportDate]
,[NextCallDate]
,[CreateDate]
,[CreatedBy]
,[IsEstimateMatch]
,[IsROMatch]
,[IsDriveable]
,[ModifiedDate]
,[UpdatedBy]
,[AccessedBy]
,[LegacyAsgnNavId]
,[LegacyAsgnNo]
,[AssignmentStatusReasonId]
,[RentalAgencyId]
,[Estimate_Id]
,[NextCallDateUpdatedBy]
,[RentalReservationNumber]
,[IsHail]
,[InitialOriginatingCenterId]
,[UnscheduledDropId]
,[UnscheduledExplanation]
,[RepairLevelId]
,[AdjusterFirstName]
,[AdjusterLastName]
,[AdjusterPhoneExt]
,[AdjusterPhoneNumber]
,[VehicleTrim]
,[VehicleOptions]
,[AdditionalInformation]
,[DeliveryLocation]
,[DeliveryCenterId]
,[RequestedAppointmentDate]
FROM [AssignmentManagement].[dbo].[Assignments]









share|improve this question



















  • 3





    I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

    – WEI_DBA
    Mar 25 at 19:37











  • is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

    – Hasan Mahmood
    Mar 25 at 19:48











  • @WEI_DBA added a third table that might solve the problem.

    – JVasquez0823
    Mar 25 at 21:43











  • This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

    – WEI_DBA
    Mar 26 at 20:00

















-1















I have a quick question in regards to using sql-server.
I have two tables, one for insurers, and another for appointments. My goal is to create a query where I grab all the appointments that use two specific insurers. For example, I want all the assignments that use state farm and USAA as their insurer.



SELECT TOP (1000) [Id]
,[Name]
,[AddressOne]
,[AddressTwo]
,[City]
,[State]
,[Zip]
,[PrimaryPhone]
,[SecondaryPhone]
,[Fax]
,[InsurerStatusId]
,[InsuranceGroupId]
,[ModifiedDate]
,[ModifiedBy]
,[ReportInsuranceName]
,[ReportInsuranceId]
FROM [AssignmentManagement].[dbo].[Insurers]

SELECT TOP (1000) [Id]
,[AppointmentTypeId]
,[AssignmentId]
,[StaffId]
,[CalendarId]
,[AppointmentDate]
,[ScheduledDate]
,[RequestedAppointmentDate]
,[Notes]
,[Hour]
,[Minute]
,[DayOfTheWeek]
,[CenterId]
,[AppointmentStatusId]
,[RentalCar]
,[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Appointments]

SELECT TOP (1000) [Id]
,[InsurerId]
,[RepairCategoryId]
,[AssignmentStatusId]
,[OriginalCenterId]
,[OriginalStaffId]
,[LossCategoryId]
,[ClaimNumber]
,[PolicyNumber]
,[LossDate]
,[TotalLossIndicator]
,[Source]
,[PrimaryCustomerType]
,[InsuredCustomerId]
,[OwnerCustomerId]
,[ClaimCustomerId]
,[CustomerServiceRepresentativeId]
,[TransactionId]
,[Towing]
,[RentalCar]
,[IsDriveIn]
,[Deductible]
,[DeductibleStatus]
,[PhotosOnly]
,[LeftMessageSequence]
,[VehicleYear]
,[VehicleMake]
,[VehicleMakeDescription]
,[VehicleModel]
,[VehicleColor]
,[VIN]
,[Odometer]
,[LicenseNumber]
,[LicenseState]
,[VehicleLocationName]
,[VehicleAddressOne]
,[VehicleAddressTwo]
,[VehicleCity]
,[VehicleState]
,[VehicleZip]
,[VehiclePhone1]
,[VehiclePhone1Ext]
,[VehiclePhone2]
,[VehiclePhone2Ext]
,[VehicleContactFirstName]
,[VehicleContactLastName]
,[VehicleCondition]
,[VehicleNotes]
,[Impact1]
,[Impact2]
,[ClaimOfficeName]
,[AgentName]
,[AgentFirstName]
,[AgentLastName]
,[AgentAddressOne]
,[AgentAddressTwo]
,[AgentCity]
,[AgentState]
,[AgentZip]
,[AgentLicenseNumber]
,[AgentPhone]
,[AgentPhoneExt]
,[AgentFax]
,[AgentEmail]
,[PriorDamage]
,[Notes]
,[DamageNotes]
,[SpecialInstructions]
,[DispatchNotes]
,[LossNotes]
,[OtherNotes]
,[AssignmentDate]
,[ReportDate]
,[NextCallDate]
,[CreateDate]
,[CreatedBy]
,[IsEstimateMatch]
,[IsROMatch]
,[IsDriveable]
,[ModifiedDate]
,[UpdatedBy]
,[AccessedBy]
,[LegacyAsgnNavId]
,[LegacyAsgnNo]
,[AssignmentStatusReasonId]
,[RentalAgencyId]
,[Estimate_Id]
,[NextCallDateUpdatedBy]
,[RentalReservationNumber]
,[IsHail]
,[InitialOriginatingCenterId]
,[UnscheduledDropId]
,[UnscheduledExplanation]
,[RepairLevelId]
,[AdjusterFirstName]
,[AdjusterLastName]
,[AdjusterPhoneExt]
,[AdjusterPhoneNumber]
,[VehicleTrim]
,[VehicleOptions]
,[AdditionalInformation]
,[DeliveryLocation]
,[DeliveryCenterId]
,[RequestedAppointmentDate]
FROM [AssignmentManagement].[dbo].[Assignments]









share|improve this question



















  • 3





    I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

    – WEI_DBA
    Mar 25 at 19:37











  • is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

    – Hasan Mahmood
    Mar 25 at 19:48











  • @WEI_DBA added a third table that might solve the problem.

    – JVasquez0823
    Mar 25 at 21:43











  • This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

    – WEI_DBA
    Mar 26 at 20:00













-1












-1








-1








I have a quick question in regards to using sql-server.
I have two tables, one for insurers, and another for appointments. My goal is to create a query where I grab all the appointments that use two specific insurers. For example, I want all the assignments that use state farm and USAA as their insurer.



SELECT TOP (1000) [Id]
,[Name]
,[AddressOne]
,[AddressTwo]
,[City]
,[State]
,[Zip]
,[PrimaryPhone]
,[SecondaryPhone]
,[Fax]
,[InsurerStatusId]
,[InsuranceGroupId]
,[ModifiedDate]
,[ModifiedBy]
,[ReportInsuranceName]
,[ReportInsuranceId]
FROM [AssignmentManagement].[dbo].[Insurers]

SELECT TOP (1000) [Id]
,[AppointmentTypeId]
,[AssignmentId]
,[StaffId]
,[CalendarId]
,[AppointmentDate]
,[ScheduledDate]
,[RequestedAppointmentDate]
,[Notes]
,[Hour]
,[Minute]
,[DayOfTheWeek]
,[CenterId]
,[AppointmentStatusId]
,[RentalCar]
,[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Appointments]

SELECT TOP (1000) [Id]
,[InsurerId]
,[RepairCategoryId]
,[AssignmentStatusId]
,[OriginalCenterId]
,[OriginalStaffId]
,[LossCategoryId]
,[ClaimNumber]
,[PolicyNumber]
,[LossDate]
,[TotalLossIndicator]
,[Source]
,[PrimaryCustomerType]
,[InsuredCustomerId]
,[OwnerCustomerId]
,[ClaimCustomerId]
,[CustomerServiceRepresentativeId]
,[TransactionId]
,[Towing]
,[RentalCar]
,[IsDriveIn]
,[Deductible]
,[DeductibleStatus]
,[PhotosOnly]
,[LeftMessageSequence]
,[VehicleYear]
,[VehicleMake]
,[VehicleMakeDescription]
,[VehicleModel]
,[VehicleColor]
,[VIN]
,[Odometer]
,[LicenseNumber]
,[LicenseState]
,[VehicleLocationName]
,[VehicleAddressOne]
,[VehicleAddressTwo]
,[VehicleCity]
,[VehicleState]
,[VehicleZip]
,[VehiclePhone1]
,[VehiclePhone1Ext]
,[VehiclePhone2]
,[VehiclePhone2Ext]
,[VehicleContactFirstName]
,[VehicleContactLastName]
,[VehicleCondition]
,[VehicleNotes]
,[Impact1]
,[Impact2]
,[ClaimOfficeName]
,[AgentName]
,[AgentFirstName]
,[AgentLastName]
,[AgentAddressOne]
,[AgentAddressTwo]
,[AgentCity]
,[AgentState]
,[AgentZip]
,[AgentLicenseNumber]
,[AgentPhone]
,[AgentPhoneExt]
,[AgentFax]
,[AgentEmail]
,[PriorDamage]
,[Notes]
,[DamageNotes]
,[SpecialInstructions]
,[DispatchNotes]
,[LossNotes]
,[OtherNotes]
,[AssignmentDate]
,[ReportDate]
,[NextCallDate]
,[CreateDate]
,[CreatedBy]
,[IsEstimateMatch]
,[IsROMatch]
,[IsDriveable]
,[ModifiedDate]
,[UpdatedBy]
,[AccessedBy]
,[LegacyAsgnNavId]
,[LegacyAsgnNo]
,[AssignmentStatusReasonId]
,[RentalAgencyId]
,[Estimate_Id]
,[NextCallDateUpdatedBy]
,[RentalReservationNumber]
,[IsHail]
,[InitialOriginatingCenterId]
,[UnscheduledDropId]
,[UnscheduledExplanation]
,[RepairLevelId]
,[AdjusterFirstName]
,[AdjusterLastName]
,[AdjusterPhoneExt]
,[AdjusterPhoneNumber]
,[VehicleTrim]
,[VehicleOptions]
,[AdditionalInformation]
,[DeliveryLocation]
,[DeliveryCenterId]
,[RequestedAppointmentDate]
FROM [AssignmentManagement].[dbo].[Assignments]









share|improve this question
















I have a quick question in regards to using sql-server.
I have two tables, one for insurers, and another for appointments. My goal is to create a query where I grab all the appointments that use two specific insurers. For example, I want all the assignments that use state farm and USAA as their insurer.



SELECT TOP (1000) [Id]
,[Name]
,[AddressOne]
,[AddressTwo]
,[City]
,[State]
,[Zip]
,[PrimaryPhone]
,[SecondaryPhone]
,[Fax]
,[InsurerStatusId]
,[InsuranceGroupId]
,[ModifiedDate]
,[ModifiedBy]
,[ReportInsuranceName]
,[ReportInsuranceId]
FROM [AssignmentManagement].[dbo].[Insurers]

SELECT TOP (1000) [Id]
,[AppointmentTypeId]
,[AssignmentId]
,[StaffId]
,[CalendarId]
,[AppointmentDate]
,[ScheduledDate]
,[RequestedAppointmentDate]
,[Notes]
,[Hour]
,[Minute]
,[DayOfTheWeek]
,[CenterId]
,[AppointmentStatusId]
,[RentalCar]
,[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Appointments]

SELECT TOP (1000) [Id]
,[InsurerId]
,[RepairCategoryId]
,[AssignmentStatusId]
,[OriginalCenterId]
,[OriginalStaffId]
,[LossCategoryId]
,[ClaimNumber]
,[PolicyNumber]
,[LossDate]
,[TotalLossIndicator]
,[Source]
,[PrimaryCustomerType]
,[InsuredCustomerId]
,[OwnerCustomerId]
,[ClaimCustomerId]
,[CustomerServiceRepresentativeId]
,[TransactionId]
,[Towing]
,[RentalCar]
,[IsDriveIn]
,[Deductible]
,[DeductibleStatus]
,[PhotosOnly]
,[LeftMessageSequence]
,[VehicleYear]
,[VehicleMake]
,[VehicleMakeDescription]
,[VehicleModel]
,[VehicleColor]
,[VIN]
,[Odometer]
,[LicenseNumber]
,[LicenseState]
,[VehicleLocationName]
,[VehicleAddressOne]
,[VehicleAddressTwo]
,[VehicleCity]
,[VehicleState]
,[VehicleZip]
,[VehiclePhone1]
,[VehiclePhone1Ext]
,[VehiclePhone2]
,[VehiclePhone2Ext]
,[VehicleContactFirstName]
,[VehicleContactLastName]
,[VehicleCondition]
,[VehicleNotes]
,[Impact1]
,[Impact2]
,[ClaimOfficeName]
,[AgentName]
,[AgentFirstName]
,[AgentLastName]
,[AgentAddressOne]
,[AgentAddressTwo]
,[AgentCity]
,[AgentState]
,[AgentZip]
,[AgentLicenseNumber]
,[AgentPhone]
,[AgentPhoneExt]
,[AgentFax]
,[AgentEmail]
,[PriorDamage]
,[Notes]
,[DamageNotes]
,[SpecialInstructions]
,[DispatchNotes]
,[LossNotes]
,[OtherNotes]
,[AssignmentDate]
,[ReportDate]
,[NextCallDate]
,[CreateDate]
,[CreatedBy]
,[IsEstimateMatch]
,[IsROMatch]
,[IsDriveable]
,[ModifiedDate]
,[UpdatedBy]
,[AccessedBy]
,[LegacyAsgnNavId]
,[LegacyAsgnNo]
,[AssignmentStatusReasonId]
,[RentalAgencyId]
,[Estimate_Id]
,[NextCallDateUpdatedBy]
,[RentalReservationNumber]
,[IsHail]
,[InitialOriginatingCenterId]
,[UnscheduledDropId]
,[UnscheduledExplanation]
,[RepairLevelId]
,[AdjusterFirstName]
,[AdjusterLastName]
,[AdjusterPhoneExt]
,[AdjusterPhoneNumber]
,[VehicleTrim]
,[VehicleOptions]
,[AdditionalInformation]
,[DeliveryLocation]
,[DeliveryCenterId]
,[RequestedAppointmentDate]
FROM [AssignmentManagement].[dbo].[Assignments]






sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 21:43







JVasquez0823

















asked Mar 25 at 19:33









JVasquez0823JVasquez0823

14 bronze badges




14 bronze badges







  • 3





    I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

    – WEI_DBA
    Mar 25 at 19:37











  • is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

    – Hasan Mahmood
    Mar 25 at 19:48











  • @WEI_DBA added a third table that might solve the problem.

    – JVasquez0823
    Mar 25 at 21:43











  • This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

    – WEI_DBA
    Mar 26 at 20:00












  • 3





    I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

    – WEI_DBA
    Mar 25 at 19:37











  • is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

    – Hasan Mahmood
    Mar 25 at 19:48











  • @WEI_DBA added a third table that might solve the problem.

    – JVasquez0823
    Mar 25 at 21:43











  • This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

    – WEI_DBA
    Mar 26 at 20:00







3




3





I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

– WEI_DBA
Mar 25 at 19:37





I don't see any relationship between the 2 tables. Is there a 3rd table that joins these 2?

– WEI_DBA
Mar 25 at 19:37













is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

– Hasan Mahmood
Mar 25 at 19:48





is [StaffId] from [Appointments] table joins [Id] from [Insurers] table?

– Hasan Mahmood
Mar 25 at 19:48













@WEI_DBA added a third table that might solve the problem.

– JVasquez0823
Mar 25 at 21:43





@WEI_DBA added a third table that might solve the problem.

– JVasquez0823
Mar 25 at 21:43













This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

– WEI_DBA
Mar 26 at 20:00





This is still unclear what tables relate to each other. We could guess that the Assignments.InsurerId = Insurers.Id and the Appointments.AssignmentId = Assignments.Id, but without seeing your schema and foreign keys, it would be just a guess. And I would rename those primary keys to something more meaning full for future reference.

– WEI_DBA
Mar 26 at 20:00












2 Answers
2






active

oldest

votes


















0














It sounds like the appointment [AssignmentId] relates to the insurer [Id] field:



-- Assuming a.AssignmentId = i.Id
-- Assuming USAA's ID = 12345 and State Farm's ID = 54321:

SELECT i.[Id]
,i.[Name]
,i.[AddressOne]
,i.[AddressTwo]
,i.[City]
,i.[State]
,i.[Zip]
,i.[PrimaryPhone]
,i.[SecondaryPhone]
,i.[Fax]
,i.[InsurerStatusId]
,i.[InsuranceGroupId]
,i.[ModifiedDate]
,i.[ModifiedBy]
,i.[ReportInsuranceName]
,i.[ReportInsuranceId]
,a.[Id]
,a.[AppointmentTypeId]
,a.[AssignmentId]
,a.[StaffId]
,a.[CalendarId]
,a.[AppointmentDate]
,a.[ScheduledDate]
,a.[RequestedAppointmentDate]
,a.[Notes]
,a.[Hour]
,a.[Minute]
,a.[DayOfTheWeek]
,a.[CenterId]
,a.[AppointmentStatusId]
,a.[RentalCar]
,a.[ScheduledBy]
FROM [AssignmentManagement].[dbo].[Insurers] i
JOIN [AssignmentManagement].[dbo].[Appointments] a
ON a.AssignmentId = i.Id
WHERE i.Id IN(12345, 54321)
ORDER BY i.ID, a.[RequestedAppointmentDate];





share|improve this answer






























    0














    You might have to join insurer table with appointments twice if you want to make sure you're only picking appointments that have both the insurers



     SELECT
    TOP (1000) A.[Id] ,
    A.[AppointmentTypeId] ,
    A.[AssignmentId] ,
    A.[StaffId] ,
    A.[CalendarId] ,
    A.[AppointmentDate] ,
    A.[ScheduledDate] ,
    A.[RequestedAppointmentDate] ,
    A.[Notes] ,
    A.[Hour] ,
    A.[Minute] ,
    A.[DayOfTheWeek] ,
    A.[CenterId] ,
    A.[AppointmentStatusId] ,
    A.[RentalCar] ,
    A.[ScheduledBy] ,
    I1.Name,
    I2.Name
    FROM
    [AssignmentManagement].[dbo].[Appointments] A
    left join
    [AssignmentManagement].[dbo].[Insurers] I1
    on A.StaffId = I1.Id
    and I1.Name = 'State Farm'
    left join
    [AssignmentManagement].[dbo].[Insurers] I2
    on A.StaffId = I2.Id
    and I2.Name = 'USAA'
    where
    I1.Name is not NULL
    and I2.Name is not NULL





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345188%2fquery-to-get-data-from-two-tables-and-return-them-together%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      It sounds like the appointment [AssignmentId] relates to the insurer [Id] field:



      -- Assuming a.AssignmentId = i.Id
      -- Assuming USAA's ID = 12345 and State Farm's ID = 54321:

      SELECT i.[Id]
      ,i.[Name]
      ,i.[AddressOne]
      ,i.[AddressTwo]
      ,i.[City]
      ,i.[State]
      ,i.[Zip]
      ,i.[PrimaryPhone]
      ,i.[SecondaryPhone]
      ,i.[Fax]
      ,i.[InsurerStatusId]
      ,i.[InsuranceGroupId]
      ,i.[ModifiedDate]
      ,i.[ModifiedBy]
      ,i.[ReportInsuranceName]
      ,i.[ReportInsuranceId]
      ,a.[Id]
      ,a.[AppointmentTypeId]
      ,a.[AssignmentId]
      ,a.[StaffId]
      ,a.[CalendarId]
      ,a.[AppointmentDate]
      ,a.[ScheduledDate]
      ,a.[RequestedAppointmentDate]
      ,a.[Notes]
      ,a.[Hour]
      ,a.[Minute]
      ,a.[DayOfTheWeek]
      ,a.[CenterId]
      ,a.[AppointmentStatusId]
      ,a.[RentalCar]
      ,a.[ScheduledBy]
      FROM [AssignmentManagement].[dbo].[Insurers] i
      JOIN [AssignmentManagement].[dbo].[Appointments] a
      ON a.AssignmentId = i.Id
      WHERE i.Id IN(12345, 54321)
      ORDER BY i.ID, a.[RequestedAppointmentDate];





      share|improve this answer



























        0














        It sounds like the appointment [AssignmentId] relates to the insurer [Id] field:



        -- Assuming a.AssignmentId = i.Id
        -- Assuming USAA's ID = 12345 and State Farm's ID = 54321:

        SELECT i.[Id]
        ,i.[Name]
        ,i.[AddressOne]
        ,i.[AddressTwo]
        ,i.[City]
        ,i.[State]
        ,i.[Zip]
        ,i.[PrimaryPhone]
        ,i.[SecondaryPhone]
        ,i.[Fax]
        ,i.[InsurerStatusId]
        ,i.[InsuranceGroupId]
        ,i.[ModifiedDate]
        ,i.[ModifiedBy]
        ,i.[ReportInsuranceName]
        ,i.[ReportInsuranceId]
        ,a.[Id]
        ,a.[AppointmentTypeId]
        ,a.[AssignmentId]
        ,a.[StaffId]
        ,a.[CalendarId]
        ,a.[AppointmentDate]
        ,a.[ScheduledDate]
        ,a.[RequestedAppointmentDate]
        ,a.[Notes]
        ,a.[Hour]
        ,a.[Minute]
        ,a.[DayOfTheWeek]
        ,a.[CenterId]
        ,a.[AppointmentStatusId]
        ,a.[RentalCar]
        ,a.[ScheduledBy]
        FROM [AssignmentManagement].[dbo].[Insurers] i
        JOIN [AssignmentManagement].[dbo].[Appointments] a
        ON a.AssignmentId = i.Id
        WHERE i.Id IN(12345, 54321)
        ORDER BY i.ID, a.[RequestedAppointmentDate];





        share|improve this answer

























          0












          0








          0







          It sounds like the appointment [AssignmentId] relates to the insurer [Id] field:



          -- Assuming a.AssignmentId = i.Id
          -- Assuming USAA's ID = 12345 and State Farm's ID = 54321:

          SELECT i.[Id]
          ,i.[Name]
          ,i.[AddressOne]
          ,i.[AddressTwo]
          ,i.[City]
          ,i.[State]
          ,i.[Zip]
          ,i.[PrimaryPhone]
          ,i.[SecondaryPhone]
          ,i.[Fax]
          ,i.[InsurerStatusId]
          ,i.[InsuranceGroupId]
          ,i.[ModifiedDate]
          ,i.[ModifiedBy]
          ,i.[ReportInsuranceName]
          ,i.[ReportInsuranceId]
          ,a.[Id]
          ,a.[AppointmentTypeId]
          ,a.[AssignmentId]
          ,a.[StaffId]
          ,a.[CalendarId]
          ,a.[AppointmentDate]
          ,a.[ScheduledDate]
          ,a.[RequestedAppointmentDate]
          ,a.[Notes]
          ,a.[Hour]
          ,a.[Minute]
          ,a.[DayOfTheWeek]
          ,a.[CenterId]
          ,a.[AppointmentStatusId]
          ,a.[RentalCar]
          ,a.[ScheduledBy]
          FROM [AssignmentManagement].[dbo].[Insurers] i
          JOIN [AssignmentManagement].[dbo].[Appointments] a
          ON a.AssignmentId = i.Id
          WHERE i.Id IN(12345, 54321)
          ORDER BY i.ID, a.[RequestedAppointmentDate];





          share|improve this answer













          It sounds like the appointment [AssignmentId] relates to the insurer [Id] field:



          -- Assuming a.AssignmentId = i.Id
          -- Assuming USAA's ID = 12345 and State Farm's ID = 54321:

          SELECT i.[Id]
          ,i.[Name]
          ,i.[AddressOne]
          ,i.[AddressTwo]
          ,i.[City]
          ,i.[State]
          ,i.[Zip]
          ,i.[PrimaryPhone]
          ,i.[SecondaryPhone]
          ,i.[Fax]
          ,i.[InsurerStatusId]
          ,i.[InsuranceGroupId]
          ,i.[ModifiedDate]
          ,i.[ModifiedBy]
          ,i.[ReportInsuranceName]
          ,i.[ReportInsuranceId]
          ,a.[Id]
          ,a.[AppointmentTypeId]
          ,a.[AssignmentId]
          ,a.[StaffId]
          ,a.[CalendarId]
          ,a.[AppointmentDate]
          ,a.[ScheduledDate]
          ,a.[RequestedAppointmentDate]
          ,a.[Notes]
          ,a.[Hour]
          ,a.[Minute]
          ,a.[DayOfTheWeek]
          ,a.[CenterId]
          ,a.[AppointmentStatusId]
          ,a.[RentalCar]
          ,a.[ScheduledBy]
          FROM [AssignmentManagement].[dbo].[Insurers] i
          JOIN [AssignmentManagement].[dbo].[Appointments] a
          ON a.AssignmentId = i.Id
          WHERE i.Id IN(12345, 54321)
          ORDER BY i.ID, a.[RequestedAppointmentDate];






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 25 at 19:49









          Russell FoxRussell Fox

          4,2811 gold badge17 silver badges22 bronze badges




          4,2811 gold badge17 silver badges22 bronze badges























              0














              You might have to join insurer table with appointments twice if you want to make sure you're only picking appointments that have both the insurers



               SELECT
              TOP (1000) A.[Id] ,
              A.[AppointmentTypeId] ,
              A.[AssignmentId] ,
              A.[StaffId] ,
              A.[CalendarId] ,
              A.[AppointmentDate] ,
              A.[ScheduledDate] ,
              A.[RequestedAppointmentDate] ,
              A.[Notes] ,
              A.[Hour] ,
              A.[Minute] ,
              A.[DayOfTheWeek] ,
              A.[CenterId] ,
              A.[AppointmentStatusId] ,
              A.[RentalCar] ,
              A.[ScheduledBy] ,
              I1.Name,
              I2.Name
              FROM
              [AssignmentManagement].[dbo].[Appointments] A
              left join
              [AssignmentManagement].[dbo].[Insurers] I1
              on A.StaffId = I1.Id
              and I1.Name = 'State Farm'
              left join
              [AssignmentManagement].[dbo].[Insurers] I2
              on A.StaffId = I2.Id
              and I2.Name = 'USAA'
              where
              I1.Name is not NULL
              and I2.Name is not NULL





              share|improve this answer



























                0














                You might have to join insurer table with appointments twice if you want to make sure you're only picking appointments that have both the insurers



                 SELECT
                TOP (1000) A.[Id] ,
                A.[AppointmentTypeId] ,
                A.[AssignmentId] ,
                A.[StaffId] ,
                A.[CalendarId] ,
                A.[AppointmentDate] ,
                A.[ScheduledDate] ,
                A.[RequestedAppointmentDate] ,
                A.[Notes] ,
                A.[Hour] ,
                A.[Minute] ,
                A.[DayOfTheWeek] ,
                A.[CenterId] ,
                A.[AppointmentStatusId] ,
                A.[RentalCar] ,
                A.[ScheduledBy] ,
                I1.Name,
                I2.Name
                FROM
                [AssignmentManagement].[dbo].[Appointments] A
                left join
                [AssignmentManagement].[dbo].[Insurers] I1
                on A.StaffId = I1.Id
                and I1.Name = 'State Farm'
                left join
                [AssignmentManagement].[dbo].[Insurers] I2
                on A.StaffId = I2.Id
                and I2.Name = 'USAA'
                where
                I1.Name is not NULL
                and I2.Name is not NULL





                share|improve this answer

























                  0












                  0








                  0







                  You might have to join insurer table with appointments twice if you want to make sure you're only picking appointments that have both the insurers



                   SELECT
                  TOP (1000) A.[Id] ,
                  A.[AppointmentTypeId] ,
                  A.[AssignmentId] ,
                  A.[StaffId] ,
                  A.[CalendarId] ,
                  A.[AppointmentDate] ,
                  A.[ScheduledDate] ,
                  A.[RequestedAppointmentDate] ,
                  A.[Notes] ,
                  A.[Hour] ,
                  A.[Minute] ,
                  A.[DayOfTheWeek] ,
                  A.[CenterId] ,
                  A.[AppointmentStatusId] ,
                  A.[RentalCar] ,
                  A.[ScheduledBy] ,
                  I1.Name,
                  I2.Name
                  FROM
                  [AssignmentManagement].[dbo].[Appointments] A
                  left join
                  [AssignmentManagement].[dbo].[Insurers] I1
                  on A.StaffId = I1.Id
                  and I1.Name = 'State Farm'
                  left join
                  [AssignmentManagement].[dbo].[Insurers] I2
                  on A.StaffId = I2.Id
                  and I2.Name = 'USAA'
                  where
                  I1.Name is not NULL
                  and I2.Name is not NULL





                  share|improve this answer













                  You might have to join insurer table with appointments twice if you want to make sure you're only picking appointments that have both the insurers



                   SELECT
                  TOP (1000) A.[Id] ,
                  A.[AppointmentTypeId] ,
                  A.[AssignmentId] ,
                  A.[StaffId] ,
                  A.[CalendarId] ,
                  A.[AppointmentDate] ,
                  A.[ScheduledDate] ,
                  A.[RequestedAppointmentDate] ,
                  A.[Notes] ,
                  A.[Hour] ,
                  A.[Minute] ,
                  A.[DayOfTheWeek] ,
                  A.[CenterId] ,
                  A.[AppointmentStatusId] ,
                  A.[RentalCar] ,
                  A.[ScheduledBy] ,
                  I1.Name,
                  I2.Name
                  FROM
                  [AssignmentManagement].[dbo].[Appointments] A
                  left join
                  [AssignmentManagement].[dbo].[Insurers] I1
                  on A.StaffId = I1.Id
                  and I1.Name = 'State Farm'
                  left join
                  [AssignmentManagement].[dbo].[Insurers] I2
                  on A.StaffId = I2.Id
                  and I2.Name = 'USAA'
                  where
                  I1.Name is not NULL
                  and I2.Name is not NULL






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 23:43









                  SaharshSaharsh

                  6666 silver badges17 bronze badges




                  6666 silver badges17 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55345188%2fquery-to-get-data-from-two-tables-and-return-them-together%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현