如何使用 LRTIM 和 RTRIM 查找无效记录并将其插入到错误表中?
我有一个查询,可以从表中的每一列中查找无效记录。但所有列的数据类型长度并不相同。我这样说是因为当我使用 LTRIM 和 RTRIM 时,它会给出错误“列“SubscriberLastName”的类型与 UNPIVOT 列表中指定的其他列的类型冲突”并且如果我 CAST 该列然后没有结果。
有人可以帮我吗?
Insert into ErrorTable (------) select (-----)
From (
select [SubscriberDataId]
,Case When ltrim(rtrim([SubscriberCode])) = '' Then [SubscriberCode] Else 'CorrectValue' end as [SubscriberCode]
,Case When ltrim(rtrim([SubscriberLastName]))= '' Then [SubscriberLastName] Else 'CorrectValue' end as [SubscriberLastName]
,Case When ltrim(rtrim([SubscriberFirstName]))= '' Then [SubscriberFirstName] Else 'CorrectValue' end as [SubscriberFirstName]
from Facets.SubscriberData) [sd]
Unpivot
(ErrorValue for FieldName in ([SubscriberCode],
[SubscriberLastName],[SubscriberFirstName] )) as x
where x.ErrorValue <> 'CorrectValue'
I have a query that finds the invalid records from each column in a table. but the length of the data type is not same for all the columns. I am saying this because when I use LTRIM and RTRIM , it gives an error "The type of column "SubscriberLastName" conflicts with the type of other columns specified in the UNPIVOT list" and if I CAST that column then no result.
Can anybody help me with that?
Insert into ErrorTable (------) select (-----)
From (
select [SubscriberDataId]
,Case When ltrim(rtrim([SubscriberCode])) = '' Then [SubscriberCode] Else 'CorrectValue' end as [SubscriberCode]
,Case When ltrim(rtrim([SubscriberLastName]))= '' Then [SubscriberLastName] Else 'CorrectValue' end as [SubscriberLastName]
,Case When ltrim(rtrim([SubscriberFirstName]))= '' Then [SubscriberFirstName] Else 'CorrectValue' end as [SubscriberFirstName]
from Facets.SubscriberData) [sd]
Unpivot
(ErrorValue for FieldName in ([SubscriberCode],
[SubscriberLastName],[SubscriberFirstName] )) as x
where x.ErrorValue <> 'CorrectValue'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要确保类型相同,而不仅仅是长度相同。
You need to make sure the TYPEs are the same, not just the lengths.