此查询返回数据集。每当我尝试按相应值对其进行排序时,它仅适用于某些列,不适用于公司 ID 和管辖区。(对 50 个值进行分页)和排序我们有“ORDER BY {查询中的 OrderBy.Parameters}" 子句。
从 xslt 我们有下面的排序代码:
<th data-orderby-column="XmlTable.FirmID">
<xsl:text>Firm ID</xsl:text>
</th>
<th data-orderby-column="XmlTable.EIN">
<xsl:text>EIN</xsl:text>
</th>
<th data-orderby-column="Vendor.Organization">
<xsl:text>Law Firm Name</xsl:text>
</th>
<th data-orderby-column="XmlTable.Jurisdiction">
<xsl:text>Jurisdiction</xsl:text>
</th>
<th data-orderby-column="CreatedDate">
<xsl:text>No Objection Date</xsl:text>
</th>
选择和排序的语句是:
<Statement Name="SearchSATS" Transform="{Table}.Search.xslt" Query="
DECLARE @Count int;
DECLARE @XmlTable TABLE (RowNumber int IDENTITY(0,1), IdentityID int, FirmID nvarchar(50), FirmStatus nvarchar(50), Jurisdiction nvarchar(50), TrainingCompletion datetime, EIN nvarchar(50), ContractCreatedPerson nvarchar(255));
INSERT INTO @XmlTable (IdentityID, FirmID, FirmStatus, Jurisdiction, TrainingCompletion, EIN, ContractCreatedPerson)
SELECT TOP (@Batch) {Table}.{Table}ID ,
(SELECT TOP 1 CollectionMember.CollectionMember FROM CollectionMember WITH (NOLOCK) INNER JOIN Collection WITH (NOLOCK) ON Collection.CollectionID = CollectionMember.CollectionID
WHERE Collection.Collection = 'LMWS ID' AND CollectionMember.SourceObjectID = ImportForm.AssignedOrganizationID),
CASE
WHEN Contract.ContractID IS NULL THEN 'GSE Contract Required'
WHEN Training.VerifiedDate IS NOT NULL AND Contract.Status = 'LRA Executed' THEN 'No Objection - Notified'
WHEN Training.VerifiedDate IS NOT NULL AND Contract.Status <> 'LRA Executed' THEN 'Training Complete'
WHEN Contract.Status = 'LRA Executed' THEN 'GSE Contract Signed'
WHEN Contract.Status = 'LRA Sent' THEN 'GSE Contract Sent'
WHEN Contract.Status = 'LRA Received' THEN 'GSE Contract Received'
ELSE 'GSE Contract Required'
END,
CONVERT(xml, XmlData).value('(/ImportFormXml/AssignedOrganization_Regions_0_State)[1]', 'nvarchar(255)') ,
(SELECT TOP 1 VerifiedDate FROM Contact WITH (NOLOCK) WHERE ObjectID = Contract.VendorID AND Contact.Object = 'Organization' AND Contact.ContactType = 'Training'),
Contact.TIN,
(SELECT Person FROM Person WITH (NOLOCK) WHERE PersonID = Contract.CreatedPersonID)
FROM {From.ForeignKey}
INNER JOIN Contact WITH (NOLOCK)
ON Contact.ContactID = Vendor.ContactID
LEFT OUTER JOIN Contact Training WITH (NOLOCK)
ON Training.Object = 'Organization'
AND Training.ObjectID = Vendor.OrganizationID
AND Training.ContactType = 'Training'
INNER JOIN ObjectLink WITH (NOLOCK)
ON ObjectLink = 'LRA Contract Form Link'
AND ObjectLink.PrimaryObjectID = Contract.ContractID
AND ObjectLink.PrimaryObject = 'Contract'
AND ObjectLink.LinkedObject = 'ImportForm'
INNER JOIN ImportForm WITH (NOLOCK)
ON ImportForm.ImportFormID = ObjectLink.LinkedObjectID
WHERE {Where.Basic} AND {Where.Filters}
AND (@FirmStatus IS NULL OR @FirmStatus =
CASE
WHEN Contract.ContractID IS NULL THEN 'GSE Contract Required'
WHEN Training.VerifiedDate IS NOT NULL AND Contract.Status = 'LRA Executed' THEN 'No Objection - Notified'
WHEN Training.VerifiedDate IS NOT NULL AND Contract.Status <> 'LRA Executed' THEN 'Training Complete'
WHEN Contract.Status = 'LRA Executed' THEN 'GSE Contract Signed'
WHEN Contract.Status = 'LRA Sent' THEN 'GSE Contract Sent'
WHEN Contract.Status = 'LRA Received' THEN 'GSE Contract Received'
ELSE 'GSE Contract Required'
END
)
AND EXISTS (SELECT 1 FROM ImportForm WITH (NOLOCK)
WHERE AssignedOrganizationID = Contract.VendorID
AND CONVERT(xml, XmlData).value('(/ImportFormXml/QuestionContractYesNo)[1]', 'nvarchar(max)') = 'Yes'
AND ImportForm.Status = 'Reviewed'
AND ImportForm.ImportFormType = 'No Objection'
)
ORDER BY {OrderBy.Parameters}
SET @Count = @@ROWCOUNT
IF @DisplaySize = 0 SET @DisplaySize = @Count
SELECT {Select.ForeignKeyLabel},
@Count AS RecordCount,
XmlTable.Jurisdiction,
XmlTable.FirmID,
XmlTable.TrainingCompletion,
XmlTable.FirmStatus
FROM {From.ForeignKey}
INNER JOIN @XmlTable XmlTable ON XmlTable.IdentityID = {Table}.{Table}ID
WHERE
XmlTable.RowNumber BETWEEN @RecordStart AND (@RecordStart + @DisplaySize - 1)
ORDER BY
XmlTable.RowNumber
">
<Parameters>
<Parameter Name="Batch" DbType="Int32" Value="50000"/>
<Parameter Name="FirmStatus" DbType="String"/>
</Parameters>
</Statement>