個人や企業のデータを保持するテーブルがあり、個人や企業のデータが見つからない場合はデフォルト値を取得したいとします。私が見つけていないが、この場合には, the same for companies, if the
CompanyCustomerAccountId third row
ある個人のためのデフォルト値を取得する場合は、それを取得するテーブルで見つかっIndividualCustomerAccountId
場合は二つのパラメータIndividualCustomerAccountId
とCompanyCustomerAccountId
をとる関数を作成したい表結果が見つからない場合はsqlがデフォルトの行を選択します
CustomerAccountId CustomerAccountType DueDays IsAdjustable isDefaultForIndividual isDefaultForCompany
1 Individual 10 true false false
2 Company 20 false false false
null null 5 false true false
null null 30 true false true
を持っていますこの場合はis found retrieve it, if not get the default value for the companies which is
第4行目となる。
なし会社のでfirst and fourth rows
を返す必要があり、我々は2番目のパラメータとして
を最初のパラメータとCompanyCustomerAccountId
としてIndividualCustomerAccountId
を受け入れる目的球を作成したサンプル入力
MyFunc(1 , 2)
がfirst and second rows
MyFunc(1 , 50)
を返すべきであると仮定テーブルにはCustomerAccountId
50
がありますので、cのデフォルト値を取得します顧客のアカウントID 100
とは個人が見つからないのでsecond and third rows
を返す必要がありますfourth row
MyFunc(100 , 2)
あるompaniesので、我々はthird row
ある個人のためのデフォルト値を取得し、我々はcustomerAccountId
2で会社を持っているので、我々は単にretriveことができますそれはテーブルから。
私は、これらの結果に
[この役立つかもしれない](http://stackoverflow.com/a/285823/5707687) –
私はあなたのデータを正規化することは選択肢ではないと仮定するつもりですか?より優れた設計であれば、照会が容易になります。 – Crowcoder
@Crowcoderあなたは正しかったですが残念ながらDB設計を変更することはできません –