peters
peters

Reputation: 79

Case statements with multiple joins

I have these two select statements that are using three tables. I need to be able to create a table from these and say if select statement 1 then assign the user a value = 10, if select statement 2 then assign user_id a value = 7. In my new table I would have the user_id and value it was assigned if the case statement evaluates to true. I keep getting syntax errors for any case statements I write

SELECT m.user_id,f.manager_id
from sales b
JOIN promotions m on b.user_id = m.user_id
JOIN promotions f on b.user_sub_id = f.user_id
where m.address = f.address
and m.post = '95103'

SELECT m.user_id,f.manager_id
from sales b
JOIN promotions m on b.user_id = m.user_id
JOIN promotions f on b.user_sub_id = f.user_id
where m.address = f.address
and m.post = '98746'
AND f.address <> 'NULL' AND
NOT EXISTS (SELECT 1
FROM payments c
WHERE c.member_id = b.user_sub_id AND
c.status <> 'NULL'
AND c.info = 'T'
)

Upvotes: 0

Views: 754

Answers (1)

Migo
Migo

Reputation: 151

What have you done so far? No case statement needed.

select * 
into #Output
from (
-- select statement 1
select 10 as UserValue
, m.user_id
, f.manager_id

union all

-- select statement 2
select 7 as UserValue
, m.user_id
, f.manager_id 
) a

Upvotes: 2

Related Questions