我有一个存储过程
ALTER PROCEDURE [dbo].[solar_zip_tier_acl_zip_export]
@affiliate_id int
AS
BEGIN
SET NOCOUNT ON;
declare @tier_date varchar(6)
exec solar_zip_tier_select_active_date @tier_date output
SELECT DISTINCT
zip,
state
FROM solar_zip_tier_mapping_view sztm (NOLOCK)
JOIN solar_zip_tier_acl acl (NOLOCK)
ON acl.tier_id = sztm.tier_id
AND (acl.buyer_id = sztm.buyer_id
OR acl.buyer_id = 0)
JOIN buyers b (NOLOCK)
ON b.buyer_id = sztm.buyer_id
JOIN solar_zip_tiers szt (NOLOCK)
ON szt.tier_id = sztm.tier_id
WHERE sztm.tier_date = @tier_date
AND acl.affiliate_id = @affiliate_id
AND sztm.active > 0
AND b.active > 0
AND szt.active > 0
ORDER BY zip
返回结果的方式是
Zip State
01001
01001 MA
01002
01002 MA
01003
01003 MA
它产生了2行,其中一行有状态,另一行没有状态,我该怎么修改它,所以只产生带数据的行? 我希望结果为
Zip State
01001 MA
01002 MA
01003 MA
答案 0 :(得分:0)
SELECT DISTINCT
zip,
state
FROM solar_zip_tier_mapping_view sztm (NOLOCK)
JOIN solar_zip_tier_acl acl (NOLOCK)
ON acl.tier_id = sztm.tier_id
AND (acl.buyer_id = sztm.buyer_id
OR acl.buyer_id = 0)
JOIN buyers b (NOLOCK)
ON b.buyer_id = sztm.buyer_id
JOIN solar_zip_tiers szt (NOLOCK)
ON szt.tier_id = sztm.tier_id
WHERE sztm.tier_date = @tier_date
AND acl.affiliate_id = @affiliate_id
AND sztm.active > 0
AND b.active > 0
AND szt.active > 0
AND STATE IS NOT NULL AND STATE IS NOT ''
ORDER BY zip