2011-01-28 119 views
1

我在下面有一個簡單的查詢。但我不知道爲什麼我得到一個無效的列名錯誤的字段名稱和錯誤值在where子句。列名無效ERROR

select * From (
    select [SubscriberDataId] 
    ,Case When ISNUMERIC([SubscriberCode]) = 0 Then cast([SubscriberCode]as varchar(9)) Else '~' end as [SubscriberCode] 
    ,Case When ISDATE([Dob]) = 0 Then Cast([Dob] as Varchar(9)) Else '~' end as [Dob] 
    ,Case When ISNUMERIC([FacetsGroup]) = 0 Then cast([FacetsGroup]as varchar(9)) Else '~' end as [FacetsGroup] 
    from Facets.SubscriberData) [sd] 
    Unpivot 
    (ErrorValue for FieldName in ([SubscriberCode], 
    [Dob],[FacetsGroup])) as x 
    where x.ErrorValue <> '~' and 
      NOT EXISTS (SELECT * 
    FROM Elig.dbo.ErrorTable 
       WHERE TableName = facets.SubscriberData 
    AND FieldName IN([x].[SubscriberCode],[x].[Dob],[x].[FacetsGroup]) 
       AND ErrorValue IN([SubscriberCode],[Dob],[FacetsGroup])) 
+5

你已經在你前面的問題得到了足夠的格式的例子,可以開始自己修復它,如果你想幫助 – 2011-01-28 20:43:46

回答

1

嘗試

select * From 
    (select [SubscriberDataId], 
     Case When ISNUMERIC([SubscriberCode]) = 0 
      Then cast([SubscriberCode]as varchar(9)) 
      Else '~' end as [SubscriberCode], 
     Case When ISDATE([Dob]) = 0 
      Then Cast([Dob] as Varchar(9)) 
      Else '~' end as [Dob], 
     Case When ISNUMERIC([FacetsGroup]) = 0 
      Then cast([FacetsGroup]as varchar(9)) 
      Else '~' end as [FacetsGroup] 
from Facets.SubscriberData) [sd] 
Unpivot (ErrorValue for FieldName in ([SubscriberCode], [Dob],[FacetsGroup])) as x where x.ErrorValue <> '~' 
and NOT EXISTS (SELECT * FROM Elig.dbo.ErrorTable     
       WHERE TableName = facets.SubscriberData  
       AND FieldName IN('[x].[SubscriberCode]','[x].[Dob]','[x].[FacetsGroup]') 
       AND ErrorValue IN('[SubscriberCode]','[Dob]','[FacetsGroup]'))