您好我正在尝试在sql server中运行以下存储过程,并给出以下错误
在预期条件的上下文中指定的非布尔类型的表达式,接近' LeadStatus'。
存储过程只是更新字段' RecQuality'基于LeadStatus'的价值column..RecQuality是一个整数字段。找到下面的存储过程
Create Procedure [dbo].[ETL_SetRecordWeightsForLeadStatus]
@TableName as varchar(50) ,
@FieldName as varchar(50)
As
Begin
Declare @Sql nvarchar(500);
SET @Sql = 'Update [dbo].[' + @TableName + ']
Set RecQuality = Case When [' + @FieldName + '] = ''Tier-1'' Then RecQuality +100
When [' + @FieldName + '] = ''Tier-2'' Then RecQuality +90
When [' + @FieldName + '] = ''Tier-3'' Then RecQuality +80
When [' + @FieldName + '] = ''Tier-4'' Then RecQuality +70
When [' + @FieldName + '] = ''Tier-5'' Then RecQuality +60
When [' + @FieldName + '] = ''Tier-6'' Then RecQuality +50
When [' + @FieldName + '] = ''Tier-0'' Then RecQuality +40
Else RecQuality +0 End
Where LEN([' + @FieldName + ']) > 0 ';
Execute sp_executesql @Sql;
End
当我运行下面的Sql时,单独用值运行正常的参数替换参数。
Update [dbo].[CannonListTest_WithStatus_deduped1]
Set RecQuality = Case When LeadStatus = 'Tier-1' Then RecQuality +100
When LeadStatus= 'Tier-2' Then RecQuality +90
When LeadStatus = 'Tier-3' Then RecQuality +80
When LeadStatus = 'Tier-4' Then RecQuality +70
When LeadStatus = 'Tier-5' Then RecQuality +60
When LeadStatus = 'Tier-6' Then RecQuality +50
When LeadStatus = 'Tier-0' Then RecQuality +40
Else RecQuality +0 End
Where LEN(LeadStatus) > 0
我无法准确找到问题所在。可以帮助我解决错误吗?
答案 0 :(得分:0)
用于存储查询的nvarchar
变量(@Sql
)对于您使用的查询来说不够大。所以改变
Declare @Sql nvarchar(500);
到
Declare @Sql nvarchar(max);