function - SQL Server 2008R2 Join One To Many -
i have 2 tables, table names case , party. both tables have case_id. have 1 many relationship (1 case has several parties). each case, @ least 1 party has marked primary party (a yes/no field in party table). need find cases no party has been assigned on case.
so far, have query pulls parties not primary parties on each case – need find cases have no primary party designated. (i have constraint on type of cases). using sql server 2008r2. in advance help!
select [case].case_id, [case].case_number, count(party.case_id)as party_count party join [case] on [case].case_id = party.case_id [case].case_type_id in(12,13,15) , party.primary_party = '' group [case].case_id, [case].case_number
try this:
select * case c left join p on p.case_id = c.case_id , p.primary_party != '' p.case_id null this selects cases not have associated non-empty primary party.
as side note, recommend using null represent "no primary party" rather empty string.
Comments
Post a Comment