が含まれています。これは、以下のフォーラムのポストからの、次のとおりです。 Case statement with containsCaseステートメントは
私は新しいポストを書いていますことをお詫び申し上げますんが、私は、私は私の最初のフォーラムで重要な情報の多くを逃した実現私がこれを付け加えれば、これは事柄を混乱させ、私はちょうどやり直すと思った。上記のコードでは
select
ContactGroupType.GroupID,FormattedName,GroupName,FormattedName,ContactGroupType.GroupType,[Address]
from ContactGroupContacts
left join ContactGroupType on ContactGroupContacts.GroupID = ContactGroupType.GroupID
left join ContactContacts on ContactGroupContacts.ContactID = ContactContacts.ContactID
left join ContactGroup_Details on ContactGroupType.GroupID = ContactGroupDetails.GroupID
left join Addresses on ContactGroupDetails.AddressID = Addresses.AddressID
left join ContactGroups on ContactGroupType.groupID = ContactGroups.groupID
where
ExpiryDate is null and
[Address] in ('9 fox ave','10 bush')
order by
FormattedAddress,
grouptype asc
、私は取得しています以下の結果:
Group_Ref | GroupName | Contact_Name | GroupType | Address
17766 MR D & N Goodwin Dan Goodwin Current Tenant 10 bush
17766 MR D & N Goodwin Nikki Goodwin Current Tenant 10 bush
17108 MRS A & P Bamer Amber Goodwin Current Tenant 9 fox ave
17108 MRS A & P Bamer Peter Goodwin Current Tenant 9 fox ave
2018 MR O & E Tofu Ola Tofu Former Tenant 9 fox ave
11875 MR D & N Biggs Dan Biggs Former Tenant 9 fox ave
12952 MR R & E Spur Richard Spur Former Tenant 9 fox ave
13193 MS N & E Snalles Nicole Snalles Former Tenant 9 fox ave
は、私は以下のSQLコードを持っている(私はSSMS 2016を使用しています)
以下を示すためにcase文を書く必要があります。したがって、現在の住所に1つまたは複数の現在のテナントがある場合は、必ず「1」を表示する必要があります。住所に1人以上の現在の元テナントがある場合は、「2」を表示する必要があります。下記を参照してください。
Group_Ref | GroupName | Contact_Name | GroupType | Address | Case
17766 MR D & N Goodwin Dan Goodwin Current Tenant 10 bush 1
17766 MR D & N Goodwin Nikki Goodwin Current Tenant 10 bush 1
17108 MRS A & P Bamer Amber Goodwin Current Tenant 9 fox ave 2
17108 MRS A & P Bamer Peter Goodwin Current Tenant 9 fox ave 2
2018 MR O & E Tofu Ola Tofu Former Tenant 9 fox ave 2
11875 MR D & N Biggs Dan Biggs Former Tenant 9 fox ave 2
12952 MR R & E Spur Richard Spur Former Tenant 9 fox ave 2
13193 MS N & E Snalles Nicole Snalles Former Tenant 9 fox ave 2
? – Jake