I need a query which writes to a table (if data is missing) and then based on the logic return a value (TRUE/FALSE) if the procedure needs to be executed.
I have following (not functional) query:
so what i'm trying to do is if:
Thanks for your help in advance. Thanks.
I have following (not functional) query:
Code:
Declare @MissingData varchar(6) = 'TRUE'
Insert INTO MissingInfoTable
(CustomerID, NoOfEntries, CustomerName, PhoneNumber, MissingDate, DateEntered, EnteredBy)
SELECT CustomerID, NoOfEntries, CustomerName, PhoneNumber,
(SELECT @MissingData =
(CASE
when COUNT(NoOfEntries) > 1 THEN 'Found duplicate data' and @MissingData = 'TRUE'
when COUNT(NoOfEntries) < 1 THEN 'Not a customer' and @MissingData = 'FALSE'
when PhoneNumber IS NULL THEN 'Missing Phone number' and @MissingData = 'TRUE'
when COUNT(NoOfEntries) = 1 THEN @MissingData = 'FALSE'
ELSE ''
END) as ValueString
from #CustomerInfo) as valueString , getdate(), 'Employee-Amanda'
from #CustomerInfo
Code:
CASE 1. @MissingData = 'TRUE' and ValueString = 'Found duplicate data' Insert (CustomerID, NoOfEntries, CustomerName, PhoneNumber, MissingDate, DateEntered, EnteredBy) into MissingInfoTable and return value for MissingData = 'True'
CASE 2. @MissingData = 'FALSE', then do not insert anything into MissingInfoTable just return the value for MissingData = 'FALSE'
CASE 3. @MissingData = 'TRUE' and ValueString ='Missing Phone number' Insert (CustomerID, NoOfEntries, CustomerName, PhoneNumber, MissingDate, DateEntered, EnteredBy) into MissingInfoTable and return value for MissingData = 'True'
CASE 4. @MissingData = 'FALSE', then do not insert anything into MissingInfoTable just return the value for MissingData = 'FALSE'