0
  1. I have created a table in Data Extension that contains 4 fields. All fields are Nullable. One field Name is Checked. In that field the values are Yes and No according to the requirement. Now I want Max count of either YES or NO and that need to be saved in another table in a new column.

  2. Can anyone help me in building this query.

Currently using:

Select Check, CASE
                  COUNT(distinct Winner)
                  WHEN Yes THEN 'Yes'
                  ELSE 'No'
              END as winner
FROM Test_Table

I changed my Query this way:

select max(Final) as Winner from (
                Select distinct Seafood, max(Seafood) as Final
                 from Tirumala_Testing_New
                  group by Seafood
                         ) A

This is not printing the max value it is just taking the random value how to display max value

  • Select Check, case count(distinct Winner) when Yes then 'Yes' else 'No' end as winner from Test_Table(I tried this) But it is not working – MarketingCloud Oct 27 '17 at 16:44
  • 1
    Please be more specific than it is not working. – Adrian Larson Oct 27 '17 at 16:56
  • Am getting syntax error near the variable name Check – MarketingCloud Oct 27 '17 at 16:58
  • You aren't using the case function properly – Samuel Dare Oct 27 '17 at 17:15
  • Count distinct winner is an agregate function and cannot return a string "yes" – Samuel Dare Oct 27 '17 at 17:18
0

Try this:

SELECT 


Max(Winner) as Winner


FROM 

(CASE WHEN Checked IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column1 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column2 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New UNION
CASE WHEN Column3 IS NOT NULL THEN 1 END as Winner FROM Tirumala_Testing_New) x
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.