Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 82.62 KB | None | 0 0
  1. exec sp_executesql N'SELECT
  2.    [UnionAll2].[Name] AS [C1],
  3.    [UnionAll2].[SecurityLevel] AS [C2],
  4.    [UnionAll2].[IsDriverEnabled] AS [C3],
  5.    [UnionAll2].[MaximumTrialLossRuns] AS [C4],
  6.    [UnionAll2].[InterlocationSharingLevel] AS [C5],
  7.    [UnionAll2].[DaysPriorOrderingLossRunnNotification] AS [C6],
  8.    [UnionAll2].[SendEmailsFlag] AS [C7],
  9.    [UnionAll2].[AllowViewAcordXml] AS [C8],
  10.    [UnionAll2].[IsAppulateTeam] AS [C9],
  11.    [UnionAll2].[UplinkOcrEnabled] AS [C10],
  12.    [UnionAll2].[LoginLockingEnabled] AS [C11],
  13.    [UnionAll2].[UplinkSettings] AS [C12],
  14.    [UnionAll2].[ShortName] AS [C13],
  15.    [UnionAll2].[InsuredDeletionRestrictionType] AS [C14],
  16.    [UnionAll2].[AllowNonAdminUsersToSelectDeselectMarkets] AS [C15],
  17.    [UnionAll2].[IsDecliningSubmissionAllowed] AS [C16],
  18.    [UnionAll2].[EmsRestrictedDesignations] AS [C17],
  19.    [UnionAll2].[EmsAllowUserControlDesignations] AS [C18],
  20.    [UnionAll2].[IsVisibleForMarkets] AS [C19],
  21.    [UnionAll2].[Id] AS [C20],
  22.    [UnionAll2].[Id1] AS [C21],
  23.    [UnionAll2].[Id2] AS [C22],
  24.    [UnionAll2].[MarketId] AS [C23],
  25.    [UnionAll2].[CompanyId] AS [C24],
  26.    [UnionAll2].[MarketId1] AS [C25],
  27.    [UnionAll2].[CompanyId1] AS [C26],
  28.    [UnionAll2].[C3] AS [C27],
  29.    [UnionAll2].[Id3] AS [C28],
  30.    [UnionAll2].[Name1] AS [C29],
  31.    [UnionAll2].[DateRegistered] AS [C30],
  32.    [UnionAll2].[City] AS [C31],
  33.    [UnionAll2].[StateId] AS [C32],
  34.    [UnionAll2].[Phone] AS [C33],
  35.    [UnionAll2].[C4] AS [C34],
  36.    [UnionAll2].[LastLoginTime] AS [C35],
  37.    [UnionAll2].[C5] AS [C36],
  38.    [UnionAll2].[IsTesting] AS [C37],
  39.    [UnionAll2].[C6] AS [C38],
  40.    [UnionAll2].[C1] AS [C39],
  41.    [UnionAll2].[Id4] AS [C40],
  42.    [UnionAll2].[MarketId2] AS [C41],
  43.    [UnionAll2].[Name2] AS [C42],
  44.    [UnionAll2].[StateId1] AS [C43],
  45.    [UnionAll2].[NotificationEmail] AS [C44],
  46.    [UnionAll2].[C7] AS [C45],
  47.    [UnionAll2].[C8] AS [C46]
  48.    FROM  (SELECT
  49.        CASE WHEN ([Distinct1].[Id] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1],
  50.        [Limit4].[C4] AS [C2],
  51.        [Limit4].[Name] AS [Name],
  52.        [Limit4].[SecurityLevel] AS [SecurityLevel],
  53.        [Limit4].[IsDriverEnabled] AS [IsDriverEnabled],
  54.        [Limit4].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  55.        [Limit4].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  56.        [Limit4].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  57.        [Limit4].[SendEmailsFlag] AS [SendEmailsFlag],
  58.        [Limit4].[AllowViewAcordXml] AS [AllowViewAcordXml],
  59.        [Limit4].[IsAppulateTeam] AS [IsAppulateTeam],
  60.        [Limit4].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  61.        [Limit4].[LoginLockingEnabled] AS [LoginLockingEnabled],
  62.        [Limit4].[UplinkSettings] AS [UplinkSettings],
  63.        [Limit4].[ShortName] AS [ShortName],
  64.        [Limit4].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  65.        [Limit4].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  66.        [Limit4].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  67.        [Limit4].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  68.        [Limit4].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  69.        [Limit4].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  70.        [Limit4].[Id1] AS [Id],
  71.        [Limit4].[Id2] AS [Id1],
  72.        [Limit4].[Id3] AS [Id2],
  73.        [Limit4].[MarketId] AS [MarketId],
  74.        [Limit4].[CompanyId] AS [CompanyId],
  75.        [Limit4].[MarketId1] AS [MarketId1],
  76.        [Limit4].[CompanyId1] AS [CompanyId1],
  77.        [Limit4].[C1] AS [C3],
  78.        [Limit4].[Id] AS [Id3],
  79.        [Limit4].[Name] AS [Name1],
  80.        [Limit4].[DateRegistered] AS [DateRegistered],
  81.        [Limit4].[City] AS [City],
  82.        [Limit4].[StateId] AS [StateId],
  83.        [Limit4].[Phone] AS [Phone],
  84.        [Limit4].[C4] AS [C4],
  85.        [Limit4].[LastLoginTime] AS [LastLoginTime],
  86.        [Limit4].[C2] AS [C5],
  87.        [Limit4].[IsTesting] AS [IsTesting],
  88.        [Limit4].[C3] AS [C6],
  89.        [Distinct1].[Id] AS [Id4],
  90.        [Distinct1].[MarketId] AS [MarketId2],
  91.        [Distinct1].[Name] AS [Name2],
  92.        [Distinct1].[StateId] AS [StateId1],
  93.        [Distinct1].[NotificationEmail] AS [NotificationEmail],
  94.        CAST(NULL AS varchar(1)) AS [C7],
  95.        CAST(NULL AS varchar(1)) AS [C8]
  96.        FROM   (SELECT [Project11].[Id] AS [Id], [Project11].[Name] AS [Name], [Project11].[DateRegistered] AS [DateRegistered], [Project11].[IsTesting] AS [IsTesting], [Project11].[SecurityLevel] AS [SecurityLevel], [Project11].[IsDriverEnabled] AS [IsDriverEnabled], [Project11].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Project11].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Project11].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Project11].[SendEmailsFlag] AS [SendEmailsFlag], [Project11].[AllowViewAcordXml] AS [AllowViewAcordXml], [Project11].[IsAppulateTeam] AS [IsAppulateTeam], [Project11].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Project11].[LoginLockingEnabled] AS [LoginLockingEnabled], [Project11].[UplinkSettings] AS [UplinkSettings], [Project11].[ShortName] AS [ShortName], [Project11].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Project11].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Project11].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Project11].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Project11].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Project11].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Project11].[Id1] AS [Id1], [Project11].[City] AS [City], [Project11].[StateId] AS [StateId], [Project11].[Phone] AS [Phone], [Project11].[Id2] AS [Id2], [Project11].[LastLoginTime] AS [LastLoginTime], [Project11].[Id3] AS [Id3], [Project11].[MarketId] AS [MarketId], [Project11].[CompanyId] AS [CompanyId], [Project11].[MarketId1] AS [MarketId1], [Project11].[CompanyId1] AS [CompanyId1], [Project11].[C1] AS [C1], [Project11].[C2] AS [C2], [Project11].[C3] AS [C3], [Project11].[C4] AS [C4]
  97.            FROM ( SELECT
  98.                @p__linq__2 AS [p__linq__2],
  99.                [Project10].[Id] AS [Id],
  100.                [Project10].[Name] AS [Name],
  101.                [Project10].[DateRegistered] AS [DateRegistered],
  102.                [Project10].[IsTesting] AS [IsTesting],
  103.                [Project10].[SecurityLevel] AS [SecurityLevel],
  104.                [Project10].[IsDriverEnabled] AS [IsDriverEnabled],
  105.                [Project10].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  106.                [Project10].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  107.                [Project10].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  108.                [Project10].[SendEmailsFlag] AS [SendEmailsFlag],
  109.                [Project10].[AllowViewAcordXml] AS [AllowViewAcordXml],
  110.                [Project10].[IsAppulateTeam] AS [IsAppulateTeam],
  111.                [Project10].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  112.                [Project10].[LoginLockingEnabled] AS [LoginLockingEnabled],
  113.                [Project10].[UplinkSettings] AS [UplinkSettings],
  114.                [Project10].[ShortName] AS [ShortName],
  115.                [Project10].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  116.                [Project10].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  117.                [Project10].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  118.                [Project10].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  119.                [Project10].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  120.                [Project10].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  121.                [Project10].[Id1] AS [Id1],
  122.                [Project10].[City] AS [City],
  123.                [Project10].[StateId] AS [StateId],
  124.                [Project10].[Phone] AS [Phone],
  125.                [Project10].[Id2] AS [Id2],
  126.                [Project10].[LastLoginTime] AS [LastLoginTime],
  127.                [Project10].[Id3] AS [Id3],
  128.                [Project10].[MarketId] AS [MarketId],
  129.                [Project10].[CompanyId] AS [CompanyId],
  130.                [Project10].[MarketId1] AS [MarketId1],
  131.                [Project10].[CompanyId1] AS [CompanyId1],
  132.                [Project10].[C1] AS [C1],
  133.                [Project10].[C2] AS [C2],
  134.                [Project10].[C3] AS [C3],
  135.                [Project10].[C4] AS [C4]
  136.                FROM ( SELECT
  137.                    @p__linq__2 AS [p__linq__2],
  138.                    [Project8].[Id] AS [Id],
  139.                    [Project8].[Name] AS [Name],
  140.                    [Project8].[DateRegistered] AS [DateRegistered],
  141.                    [Project8].[IsTesting] AS [IsTesting],
  142.                    [Project8].[SecurityLevel] AS [SecurityLevel],
  143.                    [Project8].[IsDriverEnabled] AS [IsDriverEnabled],
  144.                    [Project8].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  145.                    [Project8].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  146.                    [Project8].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  147.                    [Project8].[SendEmailsFlag] AS [SendEmailsFlag],
  148.                    [Project8].[AllowViewAcordXml] AS [AllowViewAcordXml],
  149.                    [Project8].[IsAppulateTeam] AS [IsAppulateTeam],
  150.                    [Project8].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  151.                    [Project8].[LoginLockingEnabled] AS [LoginLockingEnabled],
  152.                    [Project8].[UplinkSettings] AS [UplinkSettings],
  153.                    [Project8].[ShortName] AS [ShortName],
  154.                    [Project8].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  155.                    [Project8].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  156.                    [Project8].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  157.                    [Project8].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  158.                    [Project8].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  159.                    [Project8].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  160.                    [Project8].[Id1] AS [Id1],
  161.                    [Project8].[City] AS [City],
  162.                    [Project8].[StateId] AS [StateId],
  163.                    [Project8].[Phone] AS [Phone],
  164.                    [Project8].[Id2] AS [Id2],
  165.                    [Project8].[LastLoginTime] AS [LastLoginTime],
  166.                    [Project8].[Id3] AS [Id3],
  167.                    [Project8].[MarketId] AS [MarketId],
  168.                    [Project8].[CompanyId] AS [CompanyId],
  169.                    [Project8].[MarketId1] AS [MarketId1],
  170.                    [Project8].[CompanyId1] AS [CompanyId1],
  171.                    1 AS [C1],
  172.                    CASE WHEN ( EXISTS (SELECT
  173.                        1 AS [C1]
  174.                        FROM [dbo].[CompanyToMarket] AS [Extent11]
  175.                        WHERE ([Extent11].[MarketId] = @p__linq__4) AND ([Extent11].[CompanyId] = [Project8].[Id]) AND (0 = [Extent11].[Disabled]) AND (1 = [Extent11].[MarketAccessType])
  176.                    )) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C2],
  177.                    CASE WHEN ([Project8].[AgencyAppointmentStatus] IS NULL) THEN 0 ELSE [Project8].[AgencyAppointmentStatus1] END AS [C3],
  178.                    [Project8].[C1] AS [C4]
  179.                    FROM ( SELECT
  180.                        [Project7].[Id] AS [Id],
  181.                        [Project7].[Name] AS [Name],
  182.                        [Project7].[DateRegistered] AS [DateRegistered],
  183.                        [Project7].[IsTesting] AS [IsTesting],
  184.                        [Project7].[SecurityLevel] AS [SecurityLevel],
  185.                        [Project7].[IsDriverEnabled] AS [IsDriverEnabled],
  186.                        [Project7].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  187.                        [Project7].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  188.                        [Project7].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  189.                        [Project7].[SendEmailsFlag] AS [SendEmailsFlag],
  190.                        [Project7].[AllowViewAcordXml] AS [AllowViewAcordXml],
  191.                        [Project7].[IsAppulateTeam] AS [IsAppulateTeam],
  192.                        [Project7].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  193.                        [Project7].[LoginLockingEnabled] AS [LoginLockingEnabled],
  194.                        [Project7].[UplinkSettings] AS [UplinkSettings],
  195.                        [Project7].[ShortName] AS [ShortName],
  196.                        [Project7].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  197.                        [Project7].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  198.                        [Project7].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  199.                        [Project7].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  200.                        [Project7].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  201.                        [Project7].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  202.                        [Project7].[Id1] AS [Id1],
  203.                        [Project7].[City] AS [City],
  204.                        [Project7].[StateId] AS [StateId],
  205.                        [Project7].[Phone] AS [Phone],
  206.                        [Project7].[Id2] AS [Id2],
  207.                        [Project7].[LastLoginTime] AS [LastLoginTime],
  208.                        [Project7].[Id3] AS [Id3],
  209.                        [Project7].[MarketId] AS [MarketId],
  210.                        [Project7].[CompanyId] AS [CompanyId],
  211.                        [Project7].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  212.                        [Project7].[MarketId1] AS [MarketId1],
  213.                        [Project7].[CompanyId1] AS [CompanyId1],
  214.                        [Project7].[AgencyAppointmentStatus1] AS [AgencyAppointmentStatus1],
  215.                        (SELECT
  216.                            COUNT(1) AS [A1]
  217.                            FROM   (SELECT [Extent8].[MarketId] AS [MarketId], [Extent9].[LocationId] AS [LocationId]
  218.                                FROM  [dbo].[SubmissionPackage] AS [Extent8]
  219.                                INNER JOIN [dbo].[User] AS [Extent9] ON [Extent8].[CreatorId] = [Extent9].[Id]
  220.                                WHERE (0 <> [Extent8].[Status]) AND (3 <> [Extent8].[Status]) ) AS [Filter6]
  221.                            INNER JOIN [dbo].[Location] AS [Extent10] ON [Filter6].[LocationId] = [Extent10].[Id]
  222.                            WHERE ([Filter6].[MarketId] = @p__linq__3) AND ([Extent10].[CompanyId] = [Project7].[Id])) AS [C1]
  223.                        FROM ( SELECT
  224.                            [Project5].[Id] AS [Id],
  225.                            [Project5].[Name] AS [Name],
  226.                            [Project5].[DateRegistered] AS [DateRegistered],
  227.                            [Project5].[IsTesting] AS [IsTesting],
  228.                            [Project5].[SecurityLevel] AS [SecurityLevel],
  229.                            [Project5].[IsDriverEnabled] AS [IsDriverEnabled],
  230.                            [Project5].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  231.                            [Project5].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  232.                            [Project5].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  233.                            [Project5].[SendEmailsFlag] AS [SendEmailsFlag],
  234.                            [Project5].[AllowViewAcordXml] AS [AllowViewAcordXml],
  235.                            [Project5].[IsAppulateTeam] AS [IsAppulateTeam],
  236.                            [Project5].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  237.                            [Project5].[LoginLockingEnabled] AS [LoginLockingEnabled],
  238.                            [Project5].[UplinkSettings] AS [UplinkSettings],
  239.                            [Project5].[ShortName] AS [ShortName],
  240.                            [Project5].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  241.                            [Project5].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  242.                            [Project5].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  243.                            [Project5].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  244.                            [Project5].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  245.                            [Project5].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  246.                            [Project5].[Id1] AS [Id1],
  247.                            [Project5].[City] AS [City],
  248.                            [Project5].[StateId] AS [StateId],
  249.                            [Project5].[Phone] AS [Phone],
  250.                            [Project5].[Id2] AS [Id2],
  251.                            [Project5].[LastLoginTime] AS [LastLoginTime],
  252.                            [Project5].[Id3] AS [Id3],
  253.                            [Project5].[MarketId] AS [MarketId],
  254.                            [Project5].[CompanyId] AS [CompanyId],
  255.                            [Project5].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  256.                            [Limit3].[MarketId] AS [MarketId1],
  257.                            [Limit3].[CompanyId] AS [CompanyId1],
  258.                            [Limit3].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus1]
  259.                            FROM   (SELECT
  260.                                [Project3].[Id] AS [Id],
  261.                                [Project3].[Name] AS [Name],
  262.                                [Project3].[DateRegistered] AS [DateRegistered],
  263.                                [Project3].[IsTesting] AS [IsTesting],
  264.                                [Project3].[SecurityLevel] AS [SecurityLevel],
  265.                                [Project3].[IsDriverEnabled] AS [IsDriverEnabled],
  266.                                [Project3].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  267.                                [Project3].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  268.                                [Project3].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  269.                                [Project3].[SendEmailsFlag] AS [SendEmailsFlag],
  270.                                [Project3].[AllowViewAcordXml] AS [AllowViewAcordXml],
  271.                                [Project3].[IsAppulateTeam] AS [IsAppulateTeam],
  272.                                [Project3].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  273.                                [Project3].[LoginLockingEnabled] AS [LoginLockingEnabled],
  274.                                [Project3].[UplinkSettings] AS [UplinkSettings],
  275.                                [Project3].[ShortName] AS [ShortName],
  276.                                [Project3].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  277.                                [Project3].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  278.                                [Project3].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  279.                                [Project3].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  280.                                [Project3].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  281.                                [Project3].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  282.                                [Project3].[Id1] AS [Id1],
  283.                                [Project3].[City] AS [City],
  284.                                [Project3].[StateId] AS [StateId],
  285.                                [Project3].[Phone] AS [Phone],
  286.                                [Project3].[Id2] AS [Id2],
  287.                                [Project3].[LastLoginTime] AS [LastLoginTime],
  288.                                [Project3].[Id3] AS [Id3],
  289.                                [Limit2].[MarketId] AS [MarketId],
  290.                                [Limit2].[CompanyId] AS [CompanyId],
  291.                                [Limit2].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  292.                                FROM   (SELECT
  293.                                    [Filter2].[Id4] AS [Id],
  294.                                    [Filter2].[Name1] AS [Name],
  295.                                    [Filter2].[DateRegistered] AS [DateRegistered],
  296.                                    [Filter2].[IsTesting] AS [IsTesting],
  297.                                    [Filter2].[SecurityLevel] AS [SecurityLevel],
  298.                                    [Filter2].[IsDriverEnabled] AS [IsDriverEnabled],
  299.                                    [Filter2].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  300.                                    [Filter2].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  301.                                    [Filter2].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  302.                                    [Filter2].[SendEmailsFlag] AS [SendEmailsFlag],
  303.                                    [Filter2].[AllowViewAcordXml] AS [AllowViewAcordXml],
  304.                                    [Filter2].[IsAppulateTeam] AS [IsAppulateTeam],
  305.                                    [Filter2].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  306.                                    [Filter2].[LoginLockingEnabled] AS [LoginLockingEnabled],
  307.                                    [Filter2].[UplinkSettings] AS [UplinkSettings],
  308.                                    [Filter2].[ShortName] AS [ShortName],
  309.                                    [Filter2].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  310.                                    [Filter2].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  311.                                    [Filter2].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  312.                                    [Filter2].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  313.                                    [Filter2].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  314.                                    [Filter2].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  315.                                    [Filter2].[Id5] AS [Id1],
  316.                                    [Filter2].[City] AS [City],
  317.                                    [Filter2].[StateId] AS [StateId],
  318.                                    [Filter2].[Phone] AS [Phone],
  319.                                    [Limit1].[Id] AS [Id2],
  320.                                    [Limit1].[LastLoginTime] AS [LastLoginTime],
  321.                                    [Limit1].[Id1] AS [Id3]
  322.                                    FROM   (SELECT [Extent1].[Id] AS [Id4], [Extent1].[Name] AS [Name1], [Extent1].[DateRegistered] AS [DateRegistered], [Extent1].[IsTesting] AS [IsTesting], [Extent1].[SecurityLevel] AS [SecurityLevel], [Extent1].[IsDriverEnabled] AS [IsDriverEnabled], [Extent1].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Extent1].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Extent1].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Extent1].[SendEmailsFlag] AS [SendEmailsFlag], [Extent1].[AllowViewAcordXml] AS [AllowViewAcordXml], [Extent1].[IsAppulateTeam] AS [IsAppulateTeam], [Extent1].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Extent1].[LoginLockingEnabled] AS [LoginLockingEnabled], [Extent1].[UplinkSettings] AS [UplinkSettings], [Extent1].[ShortName] AS [ShortName], [Extent1].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Extent1].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Extent1].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Extent1].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Extent1].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Extent1].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Extent2].[Id] AS [Id5], [Extent2].[City] AS [City], [Extent2].[StateId] AS [StateId], [Extent2].[Phone] AS [Phone]
  323.                                        FROM  [dbo].[CompanyFlatView] AS [Extent1]
  324.                                        INNER JOIN [dbo].[Location] AS [Extent2] ON [Extent1].[Id] = [Extent2].[CompanyId]
  325.                                        WHERE ([Extent1].[Id] <> @p__linq__0) AND ([Extent1].[DisableDate] IS NULL) AND ([Extent2].[IsPrimaryAddress] = 1) AND ( EXISTS (SELECT
  326.                                            1 AS [C1]
  327.                                            FROM [dbo].[CompanyToMarket] AS [Extent3]
  328.                                            WHERE (1 = [Extent3].[MarketAccessType]) AND ([Extent3].[MarketId] = @p__linq__1) AND ([Extent3].[CompanyId] = [Extent1].[Id])
  329.                                        )) ) AS [Filter2]
  330.                                    OUTER APPLY  (SELECT TOP (1) [Project2].[Id] AS [Id], [Project2].[LastLoginTime] AS [LastLoginTime], [Project2].[Id1] AS [Id1]
  331.                                        FROM ( SELECT
  332.                                            [Extent4].[Id] AS [Id],
  333.                                            [Extent4].[LastLoginTime] AS [LastLoginTime],
  334.                                            [Extent5].[Id] AS [Id1]
  335.                                            FROM  [dbo].[User] AS [Extent4]
  336.                                            INNER JOIN [dbo].[Location] AS [Extent5] ON [Extent4].[LocationId] = [Extent5].[Id]
  337.                                            WHERE [Extent5].[CompanyId] = [Filter2].[Id4]
  338.                                        )  AS [Project2]
  339.                                        ORDER BY [Project2].[LastLoginTime] DESC ) AS [Limit1] ) AS [Project3]
  340.                                OUTER APPLY  (SELECT TOP (1)
  341.                                    [Extent6].[MarketId] AS [MarketId],
  342.                                    [Extent6].[CompanyId] AS [CompanyId],
  343.                                    [Extent6].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  344.                                    FROM [dbo].[CompanyToMarket] AS [Extent6]
  345.                                    WHERE ([Extent6].[MarketId] = @p__linq__7) AND ([Extent6].[CompanyId] = [Project3].[Id]) ) AS [Limit2] ) AS [Project5]
  346.                            OUTER APPLY  (SELECT TOP (1)
  347.                                [Extent7].[MarketId] AS [MarketId],
  348.                                [Extent7].[CompanyId] AS [CompanyId],
  349.                                [Extent7].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  350.                                FROM [dbo].[CompanyToMarket] AS [Extent7]
  351.                                WHERE ([Extent7].[MarketId] = @p__linq__7) AND ([Extent7].[CompanyId] = [Project5].[Id]) ) AS [Limit3]
  352.                        )  AS [Project7]
  353.                    )  AS [Project8]
  354.                )  AS [Project10]
  355.            )  AS [Project11]
  356.            ORDER BY [Project11].[C4] ASC, [Project11].[Name] ASC
  357.            OFFSET 20 ROWS FETCH NEXT 20 ROWS ONLY  ) AS [Limit4]
  358.        OUTER APPLY  (SELECT DISTINCT
  359.            [Join5].[Id] AS [Id],
  360.            [Join5].[MarketId] AS [MarketId],
  361.            [Join5].[Name] AS [Name],
  362.            [Join5].[StateId] AS [StateId],
  363.            [Join5].[NotificationEmail] AS [NotificationEmail]
  364.            FROM  [dbo].[Location] AS [Extent12]
  365.            INNER JOIN  (SELECT [Extent13].[LocationId] AS [LocationId], [Extent14].[Id] AS [Id], [Extent14].[MarketId] AS [MarketId], [Extent14].[Name] AS [Name], [Extent14].[StateId] AS [StateId], [Extent14].[NotificationEmail] AS [NotificationEmail]
  366.                FROM  [dbo].[LocationToRegion] AS [Extent13]
  367.                INNER JOIN [dbo].[Region] AS [Extent14] ON [Extent14].[Id] = [Extent13].[RegionId] ) AS [Join5] ON [Extent12].[Id] = [Join5].[LocationId]
  368.            WHERE ([Extent12].[IsDeleted] <> 1) AND ([Join5].[MarketId] = @p__linq__2) AND ([Extent12].[CompanyId] = [Limit4].[Id]) ) AS [Distinct1]
  369.    UNION ALL
  370.        SELECT
  371.        2 AS [C1],
  372.        [Limit8].[C3] AS [C2],
  373.        [Limit8].[Name] AS [Name],
  374.        [Limit8].[SecurityLevel] AS [SecurityLevel],
  375.        [Limit8].[IsDriverEnabled] AS [IsDriverEnabled],
  376.        [Limit8].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  377.        [Limit8].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  378.        [Limit8].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  379.        [Limit8].[SendEmailsFlag] AS [SendEmailsFlag],
  380.        [Limit8].[AllowViewAcordXml] AS [AllowViewAcordXml],
  381.        [Limit8].[IsAppulateTeam] AS [IsAppulateTeam],
  382.        [Limit8].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  383.        [Limit8].[LoginLockingEnabled] AS [LoginLockingEnabled],
  384.        [Limit8].[UplinkSettings] AS [UplinkSettings],
  385.        [Limit8].[ShortName] AS [ShortName],
  386.        [Limit8].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  387.        [Limit8].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  388.        [Limit8].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  389.        [Limit8].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  390.        [Limit8].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  391.        [Limit8].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  392.        [Limit8].[Id1] AS [Id],
  393.        [Limit8].[Id2] AS [Id1],
  394.        [Limit8].[Id3] AS [Id2],
  395.        [Limit8].[MarketId] AS [MarketId],
  396.        [Limit8].[CompanyId] AS [CompanyId],
  397.        [Limit8].[MarketId1] AS [MarketId1],
  398.        [Limit8].[CompanyId1] AS [CompanyId1],
  399.        [Limit8].[Id] AS [Id3],
  400.        [Limit8].[Id] AS [Id4],
  401.        [Limit8].[Name] AS [Name1],
  402.        [Limit8].[DateRegistered] AS [DateRegistered],
  403.        [Limit8].[City] AS [City],
  404.        [Limit8].[StateId] AS [StateId],
  405.        [Limit8].[Phone] AS [Phone],
  406.        [Limit8].[C3] AS [C3],
  407.        [Limit8].[LastLoginTime] AS [LastLoginTime],
  408.        [Limit8].[C1] AS [C4],
  409.        [Limit8].[IsTesting] AS [IsTesting],
  410.        [Limit8].[C2] AS [C5],
  411.        CAST(NULL AS int) AS [C6],
  412.        CAST(NULL AS int) AS [C7],
  413.        CAST(NULL AS varchar(1)) AS [C8],
  414.        CAST(NULL AS varchar(1)) AS [C9],
  415.        CAST(NULL AS varchar(1)) AS [C10],
  416.        [Extent26].[Code] AS [Code],
  417.        CAST(NULL AS varchar(1)) AS [C11]
  418.        FROM   (SELECT [Project24].[Id] AS [Id], [Project24].[Name] AS [Name], [Project24].[DateRegistered] AS [DateRegistered], [Project24].[IsTesting] AS [IsTesting], [Project24].[SecurityLevel] AS [SecurityLevel], [Project24].[IsDriverEnabled] AS [IsDriverEnabled], [Project24].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Project24].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Project24].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Project24].[SendEmailsFlag] AS [SendEmailsFlag], [Project24].[AllowViewAcordXml] AS [AllowViewAcordXml], [Project24].[IsAppulateTeam] AS [IsAppulateTeam], [Project24].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Project24].[LoginLockingEnabled] AS [LoginLockingEnabled], [Project24].[UplinkSettings] AS [UplinkSettings], [Project24].[ShortName] AS [ShortName], [Project24].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Project24].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Project24].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Project24].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Project24].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Project24].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Project24].[Id1] AS [Id1], [Project24].[City] AS [City], [Project24].[StateId] AS [StateId], [Project24].[Phone] AS [Phone], [Project24].[Id2] AS [Id2], [Project24].[LastLoginTime] AS [LastLoginTime], [Project24].[Id3] AS [Id3], [Project24].[MarketId] AS [MarketId], [Project24].[CompanyId] AS [CompanyId], [Project24].[MarketId1] AS [MarketId1], [Project24].[CompanyId1] AS [CompanyId1], [Project24].[C1] AS [C1], [Project24].[C2] AS [C2], [Project24].[C3] AS [C3]
  419.            FROM ( SELECT
  420.                @p__linq__2 AS [p__linq__2],
  421.                @p__linq__5 AS [p__linq__5],
  422.                [Project23].[Id] AS [Id],
  423.                [Project23].[Name] AS [Name],
  424.                [Project23].[DateRegistered] AS [DateRegistered],
  425.                [Project23].[IsTesting] AS [IsTesting],
  426.                [Project23].[SecurityLevel] AS [SecurityLevel],
  427.                [Project23].[IsDriverEnabled] AS [IsDriverEnabled],
  428.                [Project23].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  429.                [Project23].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  430.                [Project23].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  431.                [Project23].[SendEmailsFlag] AS [SendEmailsFlag],
  432.                [Project23].[AllowViewAcordXml] AS [AllowViewAcordXml],
  433.                [Project23].[IsAppulateTeam] AS [IsAppulateTeam],
  434.                [Project23].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  435.                [Project23].[LoginLockingEnabled] AS [LoginLockingEnabled],
  436.                [Project23].[UplinkSettings] AS [UplinkSettings],
  437.                [Project23].[ShortName] AS [ShortName],
  438.                [Project23].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  439.                [Project23].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  440.                [Project23].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  441.                [Project23].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  442.                [Project23].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  443.                [Project23].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  444.                [Project23].[Id1] AS [Id1],
  445.                [Project23].[City] AS [City],
  446.                [Project23].[StateId] AS [StateId],
  447.                [Project23].[Phone] AS [Phone],
  448.                [Project23].[Id2] AS [Id2],
  449.                [Project23].[LastLoginTime] AS [LastLoginTime],
  450.                [Project23].[Id3] AS [Id3],
  451.                [Project23].[MarketId] AS [MarketId],
  452.                [Project23].[CompanyId] AS [CompanyId],
  453.                [Project23].[MarketId1] AS [MarketId1],
  454.                [Project23].[CompanyId1] AS [CompanyId1],
  455.                [Project23].[C1] AS [C1],
  456.                [Project23].[C2] AS [C2],
  457.                [Project23].[C3] AS [C3]
  458.                FROM ( SELECT
  459.                    @p__linq__2 AS [p__linq__2],
  460.                    @p__linq__5 AS [p__linq__5],
  461.                    [Project21].[Id] AS [Id],
  462.                    [Project21].[Name] AS [Name],
  463.                    [Project21].[DateRegistered] AS [DateRegistered],
  464.                    [Project21].[IsTesting] AS [IsTesting],
  465.                    [Project21].[SecurityLevel] AS [SecurityLevel],
  466.                    [Project21].[IsDriverEnabled] AS [IsDriverEnabled],
  467.                    [Project21].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  468.                    [Project21].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  469.                    [Project21].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  470.                    [Project21].[SendEmailsFlag] AS [SendEmailsFlag],
  471.                    [Project21].[AllowViewAcordXml] AS [AllowViewAcordXml],
  472.                    [Project21].[IsAppulateTeam] AS [IsAppulateTeam],
  473.                    [Project21].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  474.                    [Project21].[LoginLockingEnabled] AS [LoginLockingEnabled],
  475.                    [Project21].[UplinkSettings] AS [UplinkSettings],
  476.                    [Project21].[ShortName] AS [ShortName],
  477.                    [Project21].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  478.                    [Project21].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  479.                    [Project21].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  480.                    [Project21].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  481.                    [Project21].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  482.                    [Project21].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  483.                    [Project21].[Id1] AS [Id1],
  484.                    [Project21].[City] AS [City],
  485.                    [Project21].[StateId] AS [StateId],
  486.                    [Project21].[Phone] AS [Phone],
  487.                    [Project21].[Id2] AS [Id2],
  488.                    [Project21].[LastLoginTime] AS [LastLoginTime],
  489.                    [Project21].[Id3] AS [Id3],
  490.                    [Project21].[MarketId] AS [MarketId],
  491.                    [Project21].[CompanyId] AS [CompanyId],
  492.                    [Project21].[MarketId1] AS [MarketId1],
  493.                    [Project21].[CompanyId1] AS [CompanyId1],
  494.                    CASE WHEN ( EXISTS (SELECT
  495.                        1 AS [C1]
  496.                        FROM [dbo].[CompanyToMarket] AS [Extent25]
  497.                        WHERE ([Extent25].[MarketId] = @p__linq__4) AND ([Extent25].[CompanyId] = [Project21].[Id]) AND (0 = [Extent25].[Disabled]) AND (1 = [Extent25].[MarketAccessType])
  498.                    )) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C1],
  499.                    CASE WHEN ([Project21].[AgencyAppointmentStatus] IS NULL) THEN 0 ELSE [Project21].[AgencyAppointmentStatus1] END AS [C2],
  500.                    [Project21].[C1] AS [C3]
  501.                    FROM ( SELECT
  502.                        [Project20].[Id] AS [Id],
  503.                        [Project20].[Name] AS [Name],
  504.                        [Project20].[DateRegistered] AS [DateRegistered],
  505.                        [Project20].[IsTesting] AS [IsTesting],
  506.                        [Project20].[SecurityLevel] AS [SecurityLevel],
  507.                        [Project20].[IsDriverEnabled] AS [IsDriverEnabled],
  508.                        [Project20].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  509.                        [Project20].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  510.                        [Project20].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  511.                        [Project20].[SendEmailsFlag] AS [SendEmailsFlag],
  512.                        [Project20].[AllowViewAcordXml] AS [AllowViewAcordXml],
  513.                        [Project20].[IsAppulateTeam] AS [IsAppulateTeam],
  514.                        [Project20].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  515.                        [Project20].[LoginLockingEnabled] AS [LoginLockingEnabled],
  516.                        [Project20].[UplinkSettings] AS [UplinkSettings],
  517.                        [Project20].[ShortName] AS [ShortName],
  518.                        [Project20].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  519.                        [Project20].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  520.                        [Project20].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  521.                        [Project20].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  522.                        [Project20].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  523.                        [Project20].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  524.                        [Project20].[Id1] AS [Id1],
  525.                        [Project20].[City] AS [City],
  526.                        [Project20].[StateId] AS [StateId],
  527.                        [Project20].[Phone] AS [Phone],
  528.                        [Project20].[Id2] AS [Id2],
  529.                        [Project20].[LastLoginTime] AS [LastLoginTime],
  530.                        [Project20].[Id3] AS [Id3],
  531.                        [Project20].[MarketId] AS [MarketId],
  532.                        [Project20].[CompanyId] AS [CompanyId],
  533.                        [Project20].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  534.                        [Project20].[MarketId1] AS [MarketId1],
  535.                        [Project20].[CompanyId1] AS [CompanyId1],
  536.                        [Project20].[AgencyAppointmentStatus1] AS [AgencyAppointmentStatus1],
  537.                        (SELECT
  538.                            COUNT(1) AS [A1]
  539.                            FROM   (SELECT [Extent22].[MarketId] AS [MarketId], [Extent23].[LocationId] AS [LocationId]
  540.                                FROM  [dbo].[SubmissionPackage] AS [Extent22]
  541.                                INNER JOIN [dbo].[User] AS [Extent23] ON [Extent22].[CreatorId] = [Extent23].[Id]
  542.                                WHERE (0 <> [Extent22].[Status]) AND (3 <> [Extent22].[Status]) ) AS [Filter15]
  543.                            INNER JOIN [dbo].[Location] AS [Extent24] ON [Filter15].[LocationId] = [Extent24].[Id]
  544.                            WHERE ([Filter15].[MarketId] = @p__linq__3) AND ([Extent24].[CompanyId] = [Project20].[Id])) AS [C1]
  545.                        FROM ( SELECT
  546.                            [Project18].[Id] AS [Id],
  547.                            [Project18].[Name] AS [Name],
  548.                            [Project18].[DateRegistered] AS [DateRegistered],
  549.                            [Project18].[IsTesting] AS [IsTesting],
  550.                            [Project18].[SecurityLevel] AS [SecurityLevel],
  551.                            [Project18].[IsDriverEnabled] AS [IsDriverEnabled],
  552.                            [Project18].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  553.                            [Project18].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  554.                            [Project18].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  555.                            [Project18].[SendEmailsFlag] AS [SendEmailsFlag],
  556.                            [Project18].[AllowViewAcordXml] AS [AllowViewAcordXml],
  557.                            [Project18].[IsAppulateTeam] AS [IsAppulateTeam],
  558.                            [Project18].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  559.                            [Project18].[LoginLockingEnabled] AS [LoginLockingEnabled],
  560.                            [Project18].[UplinkSettings] AS [UplinkSettings],
  561.                            [Project18].[ShortName] AS [ShortName],
  562.                            [Project18].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  563.                            [Project18].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  564.                            [Project18].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  565.                            [Project18].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  566.                            [Project18].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  567.                            [Project18].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  568.                            [Project18].[Id1] AS [Id1],
  569.                            [Project18].[City] AS [City],
  570.                            [Project18].[StateId] AS [StateId],
  571.                            [Project18].[Phone] AS [Phone],
  572.                            [Project18].[Id2] AS [Id2],
  573.                            [Project18].[LastLoginTime] AS [LastLoginTime],
  574.                            [Project18].[Id3] AS [Id3],
  575.                            [Project18].[MarketId] AS [MarketId],
  576.                            [Project18].[CompanyId] AS [CompanyId],
  577.                            [Project18].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  578.                            [Limit7].[MarketId] AS [MarketId1],
  579.                            [Limit7].[CompanyId] AS [CompanyId1],
  580.                            [Limit7].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus1]
  581.                            FROM   (SELECT
  582.                                [Project16].[Id] AS [Id],
  583.                                [Project16].[Name] AS [Name],
  584.                                [Project16].[DateRegistered] AS [DateRegistered],
  585.                                [Project16].[IsTesting] AS [IsTesting],
  586.                                [Project16].[SecurityLevel] AS [SecurityLevel],
  587.                                [Project16].[IsDriverEnabled] AS [IsDriverEnabled],
  588.                                [Project16].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  589.                                [Project16].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  590.                                [Project16].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  591.                                [Project16].[SendEmailsFlag] AS [SendEmailsFlag],
  592.                                [Project16].[AllowViewAcordXml] AS [AllowViewAcordXml],
  593.                                [Project16].[IsAppulateTeam] AS [IsAppulateTeam],
  594.                                [Project16].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  595.                                [Project16].[LoginLockingEnabled] AS [LoginLockingEnabled],
  596.                                [Project16].[UplinkSettings] AS [UplinkSettings],
  597.                                [Project16].[ShortName] AS [ShortName],
  598.                                [Project16].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  599.                                [Project16].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  600.                                [Project16].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  601.                                [Project16].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  602.                                [Project16].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  603.                                [Project16].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  604.                                [Project16].[Id1] AS [Id1],
  605.                                [Project16].[City] AS [City],
  606.                                [Project16].[StateId] AS [StateId],
  607.                                [Project16].[Phone] AS [Phone],
  608.                                [Project16].[Id2] AS [Id2],
  609.                                [Project16].[LastLoginTime] AS [LastLoginTime],
  610.                                [Project16].[Id3] AS [Id3],
  611.                                [Limit6].[MarketId] AS [MarketId],
  612.                                [Limit6].[CompanyId] AS [CompanyId],
  613.                                [Limit6].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  614.                                FROM   (SELECT
  615.                                    [Filter11].[Id6] AS [Id],
  616.                                    [Filter11].[Name2] AS [Name],
  617.                                    [Filter11].[DateRegistered] AS [DateRegistered],
  618.                                    [Filter11].[IsTesting] AS [IsTesting],
  619.                                    [Filter11].[SecurityLevel] AS [SecurityLevel],
  620.                                    [Filter11].[IsDriverEnabled] AS [IsDriverEnabled],
  621.                                    [Filter11].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  622.                                    [Filter11].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  623.                                    [Filter11].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  624.                                    [Filter11].[SendEmailsFlag] AS [SendEmailsFlag],
  625.                                    [Filter11].[AllowViewAcordXml] AS [AllowViewAcordXml],
  626.                                    [Filter11].[IsAppulateTeam] AS [IsAppulateTeam],
  627.                                    [Filter11].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  628.                                    [Filter11].[LoginLockingEnabled] AS [LoginLockingEnabled],
  629.                                    [Filter11].[UplinkSettings] AS [UplinkSettings],
  630.                                    [Filter11].[ShortName] AS [ShortName],
  631.                                    [Filter11].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  632.                                    [Filter11].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  633.                                    [Filter11].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  634.                                    [Filter11].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  635.                                    [Filter11].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  636.                                    [Filter11].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  637.                                    [Filter11].[Id7] AS [Id1],
  638.                                    [Filter11].[City] AS [City],
  639.                                    [Filter11].[StateId] AS [StateId],
  640.                                    [Filter11].[Phone] AS [Phone],
  641.                                    [Limit5].[Id] AS [Id2],
  642.                                    [Limit5].[LastLoginTime] AS [LastLoginTime],
  643.                                    [Limit5].[Id1] AS [Id3]
  644.                                    FROM   (SELECT [Extent15].[Id] AS [Id6], [Extent15].[Name] AS [Name2], [Extent15].[DateRegistered] AS [DateRegistered], [Extent15].[IsTesting] AS [IsTesting], [Extent15].[SecurityLevel] AS [SecurityLevel], [Extent15].[IsDriverEnabled] AS [IsDriverEnabled], [Extent15].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Extent15].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Extent15].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Extent15].[SendEmailsFlag] AS [SendEmailsFlag], [Extent15].[AllowViewAcordXml] AS [AllowViewAcordXml], [Extent15].[IsAppulateTeam] AS [IsAppulateTeam], [Extent15].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Extent15].[LoginLockingEnabled] AS [LoginLockingEnabled], [Extent15].[UplinkSettings] AS [UplinkSettings], [Extent15].[ShortName] AS [ShortName], [Extent15].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Extent15].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Extent15].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Extent15].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Extent15].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Extent15].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Extent16].[Id] AS [Id7], [Extent16].[City] AS [City], [Extent16].[StateId] AS [StateId], [Extent16].[Phone] AS [Phone]
  645.                                        FROM  [dbo].[CompanyFlatView] AS [Extent15]
  646.                                        INNER JOIN [dbo].[Location] AS [Extent16] ON [Extent15].[Id] = [Extent16].[CompanyId]
  647.                                        WHERE ([Extent15].[Id] <> @p__linq__0) AND ([Extent15].[DisableDate] IS NULL) AND ([Extent16].[IsPrimaryAddress] = 1) AND ( EXISTS (SELECT
  648.                                            1 AS [C1]
  649.                                            FROM [dbo].[CompanyToMarket] AS [Extent17]
  650.                                            WHERE (1 = [Extent17].[MarketAccessType]) AND ([Extent17].[MarketId] = @p__linq__1) AND ([Extent17].[CompanyId] = [Extent15].[Id])
  651.                                        )) ) AS [Filter11]
  652.                                    OUTER APPLY  (SELECT TOP (1) [Project15].[Id] AS [Id], [Project15].[LastLoginTime] AS [LastLoginTime], [Project15].[Id1] AS [Id1]
  653.                                        FROM ( SELECT
  654.                                            [Extent18].[Id] AS [Id],
  655.                                            [Extent18].[LastLoginTime] AS [LastLoginTime],
  656.                                            [Extent19].[Id] AS [Id1]
  657.                                            FROM  [dbo].[User] AS [Extent18]
  658.                                            INNER JOIN [dbo].[Location] AS [Extent19] ON [Extent18].[LocationId] = [Extent19].[Id]
  659.                                            WHERE [Extent19].[CompanyId] = [Filter11].[Id6]
  660.                                        )  AS [Project15]
  661.                                        ORDER BY [Project15].[LastLoginTime] DESC ) AS [Limit5] ) AS [Project16]
  662.                                OUTER APPLY  (SELECT TOP (1)
  663.                                    [Extent20].[MarketId] AS [MarketId],
  664.                                    [Extent20].[CompanyId] AS [CompanyId],
  665.                                    [Extent20].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  666.                                    FROM [dbo].[CompanyToMarket] AS [Extent20]
  667.                                    WHERE ([Extent20].[MarketId] = @p__linq__7) AND ([Extent20].[CompanyId] = [Project16].[Id]) ) AS [Limit6] ) AS [Project18]
  668.                            OUTER APPLY  (SELECT TOP (1)
  669.                                [Extent21].[MarketId] AS [MarketId],
  670.                                [Extent21].[CompanyId] AS [CompanyId],
  671.                                [Extent21].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  672.                                FROM [dbo].[CompanyToMarket] AS [Extent21]
  673.                                WHERE ([Extent21].[MarketId] = @p__linq__7) AND ([Extent21].[CompanyId] = [Project18].[Id]) ) AS [Limit7]
  674.                        )  AS [Project20]
  675.                    )  AS [Project21]
  676.                )  AS [Project23]
  677.            )  AS [Project24]
  678.            ORDER BY [Project24].[C3] ASC, [Project24].[Name] ASC
  679.            OFFSET 20 ROWS FETCH NEXT 20 ROWS ONLY  ) AS [Limit8]
  680.        INNER JOIN [dbo].[CompanyCode] AS [Extent26] ON ([Extent26].[MarketId] = @p__linq__5) AND ((LEN([Extent26].[Code])) > 0) AND ((([Extent26].[CompanyId] IS NULL) AND ( EXISTS (SELECT
  681.            1 AS [C1]
  682.            FROM [dbo].[Location] AS [Extent27]
  683.            WHERE ([Extent27].[Id] = [Extent26].[LocationId]) AND ([Extent27].[CompanyId] = [Limit8].[Id]) AND (0 = [Extent27].[IsDeleted])
  684.        ))) OR ([Extent26].[CompanyId] = [Limit8].[Id]))
  685.    UNION ALL
  686.        SELECT
  687.        3 AS [C1],
  688.        [Limit12].[C3] AS [C2],
  689.        [Limit12].[Name] AS [Name],
  690.        [Limit12].[SecurityLevel] AS [SecurityLevel],
  691.        [Limit12].[IsDriverEnabled] AS [IsDriverEnabled],
  692.        [Limit12].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  693.        [Limit12].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  694.        [Limit12].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  695.        [Limit12].[SendEmailsFlag] AS [SendEmailsFlag],
  696.        [Limit12].[AllowViewAcordXml] AS [AllowViewAcordXml],
  697.        [Limit12].[IsAppulateTeam] AS [IsAppulateTeam],
  698.        [Limit12].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  699.        [Limit12].[LoginLockingEnabled] AS [LoginLockingEnabled],
  700.        [Limit12].[UplinkSettings] AS [UplinkSettings],
  701.        [Limit12].[ShortName] AS [ShortName],
  702.        [Limit12].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  703.        [Limit12].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  704.        [Limit12].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  705.        [Limit12].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  706.        [Limit12].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  707.        [Limit12].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  708.        [Limit12].[Id1] AS [Id],
  709.        [Limit12].[Id2] AS [Id1],
  710.        [Limit12].[Id3] AS [Id2],
  711.        [Limit12].[MarketId] AS [MarketId],
  712.        [Limit12].[CompanyId] AS [CompanyId],
  713.        [Limit12].[MarketId1] AS [MarketId1],
  714.        [Limit12].[CompanyId1] AS [CompanyId1],
  715.        [Limit12].[Id] AS [Id3],
  716.        [Limit12].[Id] AS [Id4],
  717.        [Limit12].[Name] AS [Name1],
  718.        [Limit12].[DateRegistered] AS [DateRegistered],
  719.        [Limit12].[City] AS [City],
  720.        [Limit12].[StateId] AS [StateId],
  721.        [Limit12].[Phone] AS [Phone],
  722.        [Limit12].[C3] AS [C3],
  723.        [Limit12].[LastLoginTime] AS [LastLoginTime],
  724.        [Limit12].[C1] AS [C4],
  725.        [Limit12].[IsTesting] AS [IsTesting],
  726.        [Limit12].[C2] AS [C5],
  727.        CAST(NULL AS int) AS [C6],
  728.        CAST(NULL AS int) AS [C7],
  729.        CAST(NULL AS varchar(1)) AS [C8],
  730.        CAST(NULL AS varchar(1)) AS [C9],
  731.        CAST(NULL AS varchar(1)) AS [C10],
  732.        CAST(NULL AS varchar(1)) AS [C11],
  733.        [Extent39].[AimAgencyId] AS [AimAgencyId]
  734.        FROM   (SELECT [Project37].[Id] AS [Id], [Project37].[Name] AS [Name], [Project37].[DateRegistered] AS [DateRegistered], [Project37].[IsTesting] AS [IsTesting], [Project37].[SecurityLevel] AS [SecurityLevel], [Project37].[IsDriverEnabled] AS [IsDriverEnabled], [Project37].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Project37].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Project37].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Project37].[SendEmailsFlag] AS [SendEmailsFlag], [Project37].[AllowViewAcordXml] AS [AllowViewAcordXml], [Project37].[IsAppulateTeam] AS [IsAppulateTeam], [Project37].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Project37].[LoginLockingEnabled] AS [LoginLockingEnabled], [Project37].[UplinkSettings] AS [UplinkSettings], [Project37].[ShortName] AS [ShortName], [Project37].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Project37].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Project37].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Project37].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Project37].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Project37].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Project37].[Id1] AS [Id1], [Project37].[City] AS [City], [Project37].[StateId] AS [StateId], [Project37].[Phone] AS [Phone], [Project37].[Id2] AS [Id2], [Project37].[LastLoginTime] AS [LastLoginTime], [Project37].[Id3] AS [Id3], [Project37].[MarketId] AS [MarketId], [Project37].[CompanyId] AS [CompanyId], [Project37].[MarketId1] AS [MarketId1], [Project37].[CompanyId1] AS [CompanyId1], [Project37].[C1] AS [C1], [Project37].[C2] AS [C2], [Project37].[C3] AS [C3]
  735.            FROM ( SELECT
  736.                @p__linq__2 AS [p__linq__2],
  737.                @p__linq__5 AS [p__linq__5],
  738.                @p__linq__6 AS [p__linq__6],
  739.                [Project36].[Id] AS [Id],
  740.                [Project36].[Name] AS [Name],
  741.                [Project36].[DateRegistered] AS [DateRegistered],
  742.                [Project36].[IsTesting] AS [IsTesting],
  743.                [Project36].[SecurityLevel] AS [SecurityLevel],
  744.                [Project36].[IsDriverEnabled] AS [IsDriverEnabled],
  745.                [Project36].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  746.                [Project36].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  747.                [Project36].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  748.                [Project36].[SendEmailsFlag] AS [SendEmailsFlag],
  749.                [Project36].[AllowViewAcordXml] AS [AllowViewAcordXml],
  750.                [Project36].[IsAppulateTeam] AS [IsAppulateTeam],
  751.                [Project36].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  752.                [Project36].[LoginLockingEnabled] AS [LoginLockingEnabled],
  753.                [Project36].[UplinkSettings] AS [UplinkSettings],
  754.                [Project36].[ShortName] AS [ShortName],
  755.                [Project36].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  756.                [Project36].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  757.                [Project36].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  758.                [Project36].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  759.                [Project36].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  760.                [Project36].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  761.                [Project36].[Id1] AS [Id1],
  762.                [Project36].[City] AS [City],
  763.                [Project36].[StateId] AS [StateId],
  764.                [Project36].[Phone] AS [Phone],
  765.                [Project36].[Id2] AS [Id2],
  766.                [Project36].[LastLoginTime] AS [LastLoginTime],
  767.                [Project36].[Id3] AS [Id3],
  768.                [Project36].[MarketId] AS [MarketId],
  769.                [Project36].[CompanyId] AS [CompanyId],
  770.                [Project36].[MarketId1] AS [MarketId1],
  771.                [Project36].[CompanyId1] AS [CompanyId1],
  772.                [Project36].[C1] AS [C1],
  773.                [Project36].[C2] AS [C2],
  774.                [Project36].[C3] AS [C3]
  775.                FROM ( SELECT
  776.                    @p__linq__2 AS [p__linq__2],
  777.                    @p__linq__5 AS [p__linq__5],
  778.                    @p__linq__6 AS [p__linq__6],
  779.                    [Project34].[Id] AS [Id],
  780.                    [Project34].[Name] AS [Name],
  781.                    [Project34].[DateRegistered] AS [DateRegistered],
  782.                    [Project34].[IsTesting] AS [IsTesting],
  783.                    [Project34].[SecurityLevel] AS [SecurityLevel],
  784.                    [Project34].[IsDriverEnabled] AS [IsDriverEnabled],
  785.                    [Project34].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  786.                    [Project34].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  787.                    [Project34].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  788.                    [Project34].[SendEmailsFlag] AS [SendEmailsFlag],
  789.                    [Project34].[AllowViewAcordXml] AS [AllowViewAcordXml],
  790.                    [Project34].[IsAppulateTeam] AS [IsAppulateTeam],
  791.                    [Project34].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  792.                    [Project34].[LoginLockingEnabled] AS [LoginLockingEnabled],
  793.                    [Project34].[UplinkSettings] AS [UplinkSettings],
  794.                    [Project34].[ShortName] AS [ShortName],
  795.                    [Project34].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  796.                    [Project34].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  797.                    [Project34].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  798.                    [Project34].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  799.                    [Project34].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  800.                    [Project34].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  801.                    [Project34].[Id1] AS [Id1],
  802.                    [Project34].[City] AS [City],
  803.                    [Project34].[StateId] AS [StateId],
  804.                    [Project34].[Phone] AS [Phone],
  805.                    [Project34].[Id2] AS [Id2],
  806.                    [Project34].[LastLoginTime] AS [LastLoginTime],
  807.                    [Project34].[Id3] AS [Id3],
  808.                    [Project34].[MarketId] AS [MarketId],
  809.                    [Project34].[CompanyId] AS [CompanyId],
  810.                    [Project34].[MarketId1] AS [MarketId1],
  811.                    [Project34].[CompanyId1] AS [CompanyId1],
  812.                    CASE WHEN ( EXISTS (SELECT
  813.                        1 AS [C1]
  814.                        FROM [dbo].[CompanyToMarket] AS [Extent38]
  815.                        WHERE ([Extent38].[MarketId] = @p__linq__4) AND ([Extent38].[CompanyId] = [Project34].[Id]) AND (0 = [Extent38].[Disabled]) AND (1 = [Extent38].[MarketAccessType])
  816.                    )) THEN cast(1 as bit) ELSE cast(0 as bit) END AS [C1],
  817.                    CASE WHEN ([Project34].[AgencyAppointmentStatus] IS NULL) THEN 0 ELSE [Project34].[AgencyAppointmentStatus1] END AS [C2],
  818.                    [Project34].[C1] AS [C3]
  819.                    FROM ( SELECT
  820.                        [Project33].[Id] AS [Id],
  821.                        [Project33].[Name] AS [Name],
  822.                        [Project33].[DateRegistered] AS [DateRegistered],
  823.                        [Project33].[IsTesting] AS [IsTesting],
  824.                        [Project33].[SecurityLevel] AS [SecurityLevel],
  825.                        [Project33].[IsDriverEnabled] AS [IsDriverEnabled],
  826.                        [Project33].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  827.                        [Project33].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  828.                        [Project33].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  829.                        [Project33].[SendEmailsFlag] AS [SendEmailsFlag],
  830.                        [Project33].[AllowViewAcordXml] AS [AllowViewAcordXml],
  831.                        [Project33].[IsAppulateTeam] AS [IsAppulateTeam],
  832.                        [Project33].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  833.                        [Project33].[LoginLockingEnabled] AS [LoginLockingEnabled],
  834.                        [Project33].[UplinkSettings] AS [UplinkSettings],
  835.                        [Project33].[ShortName] AS [ShortName],
  836.                        [Project33].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  837.                        [Project33].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  838.                        [Project33].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  839.                        [Project33].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  840.                        [Project33].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  841.                        [Project33].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  842.                        [Project33].[Id1] AS [Id1],
  843.                        [Project33].[City] AS [City],
  844.                        [Project33].[StateId] AS [StateId],
  845.                        [Project33].[Phone] AS [Phone],
  846.                        [Project33].[Id2] AS [Id2],
  847.                        [Project33].[LastLoginTime] AS [LastLoginTime],
  848.                        [Project33].[Id3] AS [Id3],
  849.                        [Project33].[MarketId] AS [MarketId],
  850.                        [Project33].[CompanyId] AS [CompanyId],
  851.                        [Project33].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  852.                        [Project33].[MarketId1] AS [MarketId1],
  853.                        [Project33].[CompanyId1] AS [CompanyId1],
  854.                        [Project33].[AgencyAppointmentStatus1] AS [AgencyAppointmentStatus1],
  855.                        (SELECT
  856.                            COUNT(1) AS [A1]
  857.                            FROM   (SELECT [Extent35].[MarketId] AS [MarketId], [Extent36].[LocationId] AS [LocationId]
  858.                                FROM  [dbo].[SubmissionPackage] AS [Extent35]
  859.                                INNER JOIN [dbo].[User] AS [Extent36] ON [Extent35].[CreatorId] = [Extent36].[Id]
  860.                                WHERE (0 <> [Extent35].[Status]) AND (3 <> [Extent35].[Status]) ) AS [Filter24]
  861.                            INNER JOIN [dbo].[Location] AS [Extent37] ON [Filter24].[LocationId] = [Extent37].[Id]
  862.                            WHERE ([Filter24].[MarketId] = @p__linq__3) AND ([Extent37].[CompanyId] = [Project33].[Id])) AS [C1]
  863.                        FROM ( SELECT
  864.                            [Project31].[Id] AS [Id],
  865.                            [Project31].[Name] AS [Name],
  866.                            [Project31].[DateRegistered] AS [DateRegistered],
  867.                            [Project31].[IsTesting] AS [IsTesting],
  868.                            [Project31].[SecurityLevel] AS [SecurityLevel],
  869.                            [Project31].[IsDriverEnabled] AS [IsDriverEnabled],
  870.                            [Project31].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  871.                            [Project31].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  872.                            [Project31].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  873.                            [Project31].[SendEmailsFlag] AS [SendEmailsFlag],
  874.                            [Project31].[AllowViewAcordXml] AS [AllowViewAcordXml],
  875.                            [Project31].[IsAppulateTeam] AS [IsAppulateTeam],
  876.                            [Project31].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  877.                            [Project31].[LoginLockingEnabled] AS [LoginLockingEnabled],
  878.                            [Project31].[UplinkSettings] AS [UplinkSettings],
  879.                            [Project31].[ShortName] AS [ShortName],
  880.                            [Project31].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  881.                            [Project31].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  882.                            [Project31].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  883.                            [Project31].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  884.                            [Project31].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  885.                            [Project31].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  886.                            [Project31].[Id1] AS [Id1],
  887.                            [Project31].[City] AS [City],
  888.                            [Project31].[StateId] AS [StateId],
  889.                            [Project31].[Phone] AS [Phone],
  890.                            [Project31].[Id2] AS [Id2],
  891.                            [Project31].[LastLoginTime] AS [LastLoginTime],
  892.                            [Project31].[Id3] AS [Id3],
  893.                            [Project31].[MarketId] AS [MarketId],
  894.                            [Project31].[CompanyId] AS [CompanyId],
  895.                            [Project31].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus],
  896.                            [Limit11].[MarketId] AS [MarketId1],
  897.                            [Limit11].[CompanyId] AS [CompanyId1],
  898.                            [Limit11].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus1]
  899.                            FROM   (SELECT
  900.                                [Project29].[Id] AS [Id],
  901.                                [Project29].[Name] AS [Name],
  902.                                [Project29].[DateRegistered] AS [DateRegistered],
  903.                                [Project29].[IsTesting] AS [IsTesting],
  904.                                [Project29].[SecurityLevel] AS [SecurityLevel],
  905.                                [Project29].[IsDriverEnabled] AS [IsDriverEnabled],
  906.                                [Project29].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  907.                                [Project29].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  908.                                [Project29].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  909.                                [Project29].[SendEmailsFlag] AS [SendEmailsFlag],
  910.                                [Project29].[AllowViewAcordXml] AS [AllowViewAcordXml],
  911.                                [Project29].[IsAppulateTeam] AS [IsAppulateTeam],
  912.                                [Project29].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  913.                                [Project29].[LoginLockingEnabled] AS [LoginLockingEnabled],
  914.                                [Project29].[UplinkSettings] AS [UplinkSettings],
  915.                                [Project29].[ShortName] AS [ShortName],
  916.                                [Project29].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  917.                                [Project29].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  918.                                [Project29].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  919.                                [Project29].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  920.                                [Project29].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  921.                                [Project29].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  922.                                [Project29].[Id1] AS [Id1],
  923.                                [Project29].[City] AS [City],
  924.                                [Project29].[StateId] AS [StateId],
  925.                                [Project29].[Phone] AS [Phone],
  926.                                [Project29].[Id2] AS [Id2],
  927.                                [Project29].[LastLoginTime] AS [LastLoginTime],
  928.                                [Project29].[Id3] AS [Id3],
  929.                                [Limit10].[MarketId] AS [MarketId],
  930.                                [Limit10].[CompanyId] AS [CompanyId],
  931.                                [Limit10].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  932.                                FROM   (SELECT
  933.                                    [Filter20].[Id8] AS [Id],
  934.                                    [Filter20].[Name3] AS [Name],
  935.                                    [Filter20].[DateRegistered] AS [DateRegistered],
  936.                                    [Filter20].[IsTesting] AS [IsTesting],
  937.                                    [Filter20].[SecurityLevel] AS [SecurityLevel],
  938.                                    [Filter20].[IsDriverEnabled] AS [IsDriverEnabled],
  939.                                    [Filter20].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns],
  940.                                    [Filter20].[InterlocationSharingLevel] AS [InterlocationSharingLevel],
  941.                                    [Filter20].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification],
  942.                                    [Filter20].[SendEmailsFlag] AS [SendEmailsFlag],
  943.                                    [Filter20].[AllowViewAcordXml] AS [AllowViewAcordXml],
  944.                                    [Filter20].[IsAppulateTeam] AS [IsAppulateTeam],
  945.                                    [Filter20].[UplinkOcrEnabled] AS [UplinkOcrEnabled],
  946.                                    [Filter20].[LoginLockingEnabled] AS [LoginLockingEnabled],
  947.                                    [Filter20].[UplinkSettings] AS [UplinkSettings],
  948.                                    [Filter20].[ShortName] AS [ShortName],
  949.                                    [Filter20].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType],
  950.                                    [Filter20].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets],
  951.                                    [Filter20].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed],
  952.                                    [Filter20].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations],
  953.                                    [Filter20].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations],
  954.                                    [Filter20].[IsVisibleForMarkets] AS [IsVisibleForMarkets],
  955.                                    [Filter20].[Id9] AS [Id1],
  956.                                    [Filter20].[City] AS [City],
  957.                                    [Filter20].[StateId] AS [StateId],
  958.                                    [Filter20].[Phone] AS [Phone],
  959.                                    [Limit9].[Id] AS [Id2],
  960.                                    [Limit9].[LastLoginTime] AS [LastLoginTime],
  961.                                    [Limit9].[Id1] AS [Id3]
  962.                                    FROM   (SELECT [Extent28].[Id] AS [Id8], [Extent28].[Name] AS [Name3], [Extent28].[DateRegistered] AS [DateRegistered], [Extent28].[IsTesting] AS [IsTesting], [Extent28].[SecurityLevel] AS [SecurityLevel], [Extent28].[IsDriverEnabled] AS [IsDriverEnabled], [Extent28].[MaximumTrialLossRuns] AS [MaximumTrialLossRuns], [Extent28].[InterlocationSharingLevel] AS [InterlocationSharingLevel], [Extent28].[DaysPriorOrderingLossRunnNotification] AS [DaysPriorOrderingLossRunnNotification], [Extent28].[SendEmailsFlag] AS [SendEmailsFlag], [Extent28].[AllowViewAcordXml] AS [AllowViewAcordXml], [Extent28].[IsAppulateTeam] AS [IsAppulateTeam], [Extent28].[UplinkOcrEnabled] AS [UplinkOcrEnabled], [Extent28].[LoginLockingEnabled] AS [LoginLockingEnabled], [Extent28].[UplinkSettings] AS [UplinkSettings], [Extent28].[ShortName] AS [ShortName], [Extent28].[InsuredDeletionRestrictionType] AS [InsuredDeletionRestrictionType], [Extent28].[AllowNonAdminUsersToSelectDeselectMarkets] AS [AllowNonAdminUsersToSelectDeselectMarkets], [Extent28].[IsDecliningSubmissionAllowed] AS [IsDecliningSubmissionAllowed], [Extent28].[EmsRestrictedDesignations] AS [EmsRestrictedDesignations], [Extent28].[EmsAllowUserControlDesignations] AS [EmsAllowUserControlDesignations], [Extent28].[IsVisibleForMarkets] AS [IsVisibleForMarkets], [Extent29].[Id] AS [Id9], [Extent29].[City] AS [City], [Extent29].[StateId] AS [StateId], [Extent29].[Phone] AS [Phone]
  963.                                        FROM  [dbo].[CompanyFlatView] AS [Extent28]
  964.                                        INNER JOIN [dbo].[Location] AS [Extent29] ON [Extent28].[Id] = [Extent29].[CompanyId]
  965.                                        WHERE ([Extent28].[Id] <> @p__linq__0) AND ([Extent28].[DisableDate] IS NULL) AND ([Extent29].[IsPrimaryAddress] = 1) AND ( EXISTS (SELECT
  966.                                            1 AS [C1]
  967.                                            FROM [dbo].[CompanyToMarket] AS [Extent30]
  968.                                            WHERE (1 = [Extent30].[MarketAccessType]) AND ([Extent30].[MarketId] = @p__linq__1) AND ([Extent30].[CompanyId] = [Extent28].[Id])
  969.                                        )) ) AS [Filter20]
  970.                                    OUTER APPLY  (SELECT TOP (1) [Project28].[Id] AS [Id], [Project28].[LastLoginTime] AS [LastLoginTime], [Project28].[Id1] AS [Id1]
  971.                                        FROM ( SELECT
  972.                                            [Extent31].[Id] AS [Id],
  973.                                            [Extent31].[LastLoginTime] AS [LastLoginTime],
  974.                                            [Extent32].[Id] AS [Id1]
  975.                                            FROM  [dbo].[User] AS [Extent31]
  976.                                            INNER JOIN [dbo].[Location] AS [Extent32] ON [Extent31].[LocationId] = [Extent32].[Id]
  977.                                            WHERE [Extent32].[CompanyId] = [Filter20].[Id8]
  978.                                        )  AS [Project28]
  979.                                        ORDER BY [Project28].[LastLoginTime] DESC ) AS [Limit9] ) AS [Project29]
  980.                                OUTER APPLY  (SELECT TOP (1)
  981.                                    [Extent33].[MarketId] AS [MarketId],
  982.                                    [Extent33].[CompanyId] AS [CompanyId],
  983.                                    [Extent33].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  984.                                    FROM [dbo].[CompanyToMarket] AS [Extent33]
  985.                                    WHERE ([Extent33].[MarketId] = @p__linq__7) AND ([Extent33].[CompanyId] = [Project29].[Id]) ) AS [Limit10] ) AS [Project31]
  986.                            OUTER APPLY  (SELECT TOP (1)
  987.                                [Extent34].[MarketId] AS [MarketId],
  988.                                [Extent34].[CompanyId] AS [CompanyId],
  989.                                [Extent34].[AgencyAppointmentStatus] AS [AgencyAppointmentStatus]
  990.                                FROM [dbo].[CompanyToMarket] AS [Extent34]
  991.                                WHERE ([Extent34].[MarketId] = @p__linq__7) AND ([Extent34].[CompanyId] = [Project31].[Id]) ) AS [Limit11]
  992.                        )  AS [Project33]
  993.                    )  AS [Project34]
  994.                )  AS [Project36]
  995.            )  AS [Project37]
  996.            ORDER BY [Project37].[C3] ASC, [Project37].[Name] ASC
  997.            OFFSET 20 ROWS FETCH NEXT 20 ROWS ONLY  ) AS [Limit12]
  998.        INNER JOIN [dbo].[AimRetailAgency] AS [Extent39] ON ([Extent39].[MarketId] = @p__linq__6) AND ( EXISTS (SELECT
  999.            1 AS [C1]
  1000.            FROM [dbo].[Location] AS [Extent40]
  1001.            WHERE ([Extent40].[Id] = [Extent39].[LocationId]) AND ([Extent40].[CompanyId] = [Limit12].[Id]) AND (0 = [Extent40].[IsDeleted])
  1002.        ))) AS [UnionAll2]
  1003.    ORDER BY [UnionAll2].[C2] ASC, [UnionAll2].[Name] ASC, [UnionAll2].[SecurityLevel] ASC, [UnionAll2].[IsDriverEnabled] ASC, [UnionAll2].[MaximumTrialLossRuns] ASC, [UnionAll2].[InterlocationSharingLevel] ASC, [UnionAll2].[DaysPriorOrderingLossRunnNotification] ASC, [UnionAll2].[SendEmailsFlag] ASC, [UnionAll2].[AllowViewAcordXml] ASC, [UnionAll2].[IsAppulateTeam] ASC, [UnionAll2].[UplinkOcrEnabled] ASC, [UnionAll2].[LoginLockingEnabled] ASC, [UnionAll2].[UplinkSettings] ASC, [UnionAll2].[ShortName] ASC, [UnionAll2].[InsuredDeletionRestrictionType] ASC, [UnionAll2].[AllowNonAdminUsersToSelectDeselectMarkets] ASC, [UnionAll2].[IsDecliningSubmissionAllowed] ASC, [UnionAll2].[EmsRestrictedDesignations] ASC, [UnionAll2].[EmsAllowUserControlDesignations] ASC, [UnionAll2].[IsVisibleForMarkets] ASC, [UnionAll2].[Id] ASC, [UnionAll2].[Id1] ASC, [UnionAll2].[Id2] ASC, [UnionAll2].[MarketId] ASC, [UnionAll2].[CompanyId] ASC, [UnionAll2].[MarketId1] ASC, [UnionAll2].[CompanyId1] ASC, [UnionAll2].[Id3] ASC, [UnionAll2].[DateRegistered] ASC, [UnionAll2].[IsTesting] ASC, [UnionAll2].[C1] ASC',N'@p__linq__0 int,@p__linq__1 int,@p__linq__7 int,@p__linq__3 int,@p__linq__2 int,@p__linq__4 int,@p__linq__5 int,@p__linq__6 int',@p__linq__0=5420,@p__linq__1=5420,@p__linq__7=5420,@p__linq__3=5420,@p__linq__2=5420,@p__linq__4=5420,@p__linq__5=5420,@p__linq__6=5420
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement