I have a SQL table called CustomData:
CustomizationId - int
SystemDtTm - datetime
ObjectId - int
Name - varchar(50)
Value - varchar(250)
BusinessDtTm - datetime
The below code fails with the following error message:
Conversion failed when converting date and/or time from character string.
I tried casting cd.Value as Date, but no luck.
declare @dateGenerated datetime = '8/26/2014'
declare @customizationIds varchar(8000) = '299'
declare @isCustomization299Allowed BIT = dbo.IsCustomizationAllowed(299, @customizationIds)
declare @isCustomization451Allowed BIT = dbo.IsCustomizationAllowed(451, @customizationIds)
declare @isCustomization792Allowed BIT = dbo.IsCustomizationAllowed(792, @customizationIds)
declare @isCustomization928Allowed BIT = dbo.IsCustomizationAllowed(928, @customizationIds)
select cd.CustomizationId, p.PremiumFinanceLoanId, p.InsurancePolicyId
from InsurancePolicy p
join CustomData cd on p.InsurancePolicyId = cd.ObjectId
where (@isCustomization299Allowed = 1 and cd.CustomizationId = 299 and Name = 'Policy Number Changed' and cd.Value = @dateGenerated)
(@isCustomization451Allowed = 1 and cd.CustomizationId = 451 and Name = 'Policy Number Changed - Generate new NFP')
(@isCustomization792Allowed = 1 and cd.CustomizationId = 792 and Name = 'Policy field Changed - Generate new NFP')
(@isCustomization928Allowed = 1 and cd.CustomizationId = 928 and Name = 'Policy Carrier Changed - Generate new NFP')