Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trying to combine 2 columns in sql query

SELECT SubscriberKey, COUNT(*) AS TotalSentLast180Days
FROM (
        SELECT s.SubscriberKey
        FROM ENT._Sent s
            INNER JOIN ENT.AllSubscribershistroyland ROCS
                ON ROCS.SubscriberKey = s.SubscriberKey
        WHERE ROCS.SLSegment__c = 'S4 - real-love' 
        AND 'S6 - real-love'
        AND s.OYBAccountID = '85208879'
        AND s.EventDate >= DATEADD(DAY, -180, GETDATE())
    ) t
GROUP BY SubscriberKey

So in the " AllSubscribershistroyland " their are 2 columns that are called ‘S4 – Dutch real-love’ and ‘S6 – real-love‘. Im trying to run the query to see how many subscribers are in those 2 columns. I cant seem to combine them but when i run the query for example with one column i do get a result back. I tried the ‘ AND ‘ to combine the 2 columns but i get an error code of "

Error saving the Query field. An expression of non-boolean type specified in a context where a condition is expected, near ‘AND’.** "

if anyone can help me i would be very grateful

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I am not entirely sure what you’re trying to do, but if you are just trying to include both of your titles in the where clause for the same column then you could use the IN Clause:

SELECT SubscriberKey, COUNT(*) AS TotalSentLast180Days
FROM (
        SELECT s.SubscriberKey
        FROM ENT._Sent s
            INNER JOIN ENT.AllSubscribershistroyland ROCS
                ON ROCS.SubscriberKey = s.SubscriberKey
        WHERE ROCS.SLSegment__c in ('S4 - real-love', 'S6 - real-love')
        AND s.OYBAccountID = '85208879'
        AND s.EventDate >= DATEADD(DAY, -180, GETDATE())
    ) t
GROUP BY SubscriberKey
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading