Today write a query SQL, which involves to a bank card binding table (table name: bankbind), I want this table of the Account line field values are split out of provinces, sub-branches,
This account bank field stores values such as "Guangdong Province, Guangdong province branch Jiangmen Branch Enping Sub-branch", "China Merchants Bank", "Beijing eight Li Zhuang branch", "Inner Mongolia Autonomous Region," and so on, the division of words involves some logical judgment, So I customized a table-valued function Getdistrictbybankbranch, the entry parameter is a bank value, return a table, containing the province, sub-branch 2 column of data, of course, a record.
Such as
SELECT * from Getdistrictbybankbranch (' Guangdong Province, Guangdong province branch Jiangmen Branch Enping Sub-branch ')
Return:
Province Branch
Guangdong Province Guangdong province Branch Jiangmen Branch Enping Sub-branch
Now, to all the records of the provinces, branches to find out, remember that there have been similar experience, but can't remember how to write SQL. One of the last teams in the development group gave the scenario, that is, using SQL outer APPLY, which is full sql:
SELECT *
From Bankbind A
OUTER APPLY Getdistrictbybankbranch (a.banksubbranch) b
Another, make a note. The persistence layer of the responsible Project uses EF, which today optimizes the Efdbcontext class's Add method to use the key to get a PO, by DBEntities. Getentitykey (entity), where DBEntities is the name of an entity container class that inherits from DbContext, which is typically specified and created when creating an edmx.
Outer of SQL APPLY