我需要进一步优化来自 this post 的存储过程结果集,我需要过滤结果集以仅显示 emailaddr 为 NULL 的记录(意味着仅显示 Invoice_DeliveryType
值为 'N' 的记录)。
在众多查询中,我尝试过:
select
Invoice_ID, 'Unknown' as Invoice_Status,
case when Invoice_Printed is null then '' else 'Y' end as Invoice_Printed,
case when Invoice_DeliveryDate is null then '' else 'Y' end as Invoice_Delivered,
(case when Invoice_DeliveryType <> 'USPS' then ''
when exists (Select 1
from dbo.Client c
Where c.Client_ID = SUBSTRING(i.Invoice_ID, 1, 6) and
c.emailaddr is not null
)
then 'Y'
else 'N'
end)
Invoice_ContactLName + ', ' + Invoice_ContactFName as ContactName,
from
dbo.Invoice
left outer join
dbo.fnInvoiceCurrentStatus() on Invoice_ID = CUST_InvoiceID
where
CUST_StatusID = 7
AND Invoice_ID = dbo.Client.Client_ID
AND dbo.client.emailaddr is NULL
order by
Inv_Created
但是我得到一个错误
The conversion of the nvarchar value '20111028995999' overflowed an int column
如何让存储过程只返回带有 DeliveryType = 'N'
的记录?
最佳答案
尝试将存储过程结果选择到临时表中,然后选择 * 来自#TempTable
关于tsql - 通过嵌套的 select case 语句过滤存储过程记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25837540/