Good evening,
I am trying to find a solution for a query but I am really confused (as MS SQL newbie )!
I have a client table. The table has many values per client. Some of then are NULLs or incorrectly completed.
I wrote a case statement with multiple checks that return values based on 'problems'.
Example: ( limited cases )
SELECT ....
CASE WHEN MAX(CSSATState) = 2 THEN
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(birthdate) Is null then 'BIRTHDATE ' ELSE '' END + '' +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND LEN(MAX(ISNULL(AFM,'')))<>9 then 'AFM ' ELSE '' END + '' +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(CertNum) Is null then 'CERTIFICATION ' ELSE '' END + '' +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(SSN) Is null then 'SSN ' ELSE '' END
ELSE '' END AS PROBLEMS
FROM CLIENT
and this query working! Result example of PROBLEMS collum is BIRTHDATE SSN for x client
Now I want one more collum that returns (if it is possible) a number that is the SUM result of numbers based on cases.
What i mean ...Example:
CASE WHEN MAX(CSSATState) = 2 THEN SUM (
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(birthdate) Is null then 10 ELSE 0 END +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND LEN(MAX(ISNULL(AFM,'')))<>9 then 10 ELSE 0 END ' +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(CertNum) Is null then 10 ELSE 0 END +
case when MIN(csatype)=0 and MAX(CLIENTCAT)= 0 AND MAX(SSN) Is null then 10 ELSE 0 END
ELSE '' END )AS RATING_PROBLEMS
FROM CLIENT
and the results of this collum will be the sum of values based on cases ..For a client with only error MAX(CertNum) is null then the result is 10, for a client with 2 problems the result are 20 and so on.
Thanks a lot for your time