Home > database >  SQL based on a form field values to decide which form associated
SQL based on a form field values to decide which form associated

Time:11-21

Select * from aa A left join (case A.t ype the when 1 then b else c end) on A.com Id=b B.i d
B, c are all in the name of the table according to the table aa type value to decide which form associated solution

CodePudding user response:

Can only use dynamic SQL,
Determine in advance how good, do SQL stitching, then the EXEC (@ SQL) or EXEC sp_executesql
There is no it,

CodePudding user response:

Like this?
 SELECT A. *, CASE WHEN A.T ype=1 THEN b.s omething ELSE c.s. omething END something 
The FROM aa A
LEFT the JOIN ON A.com Id=B b.i d
LEFT the JOIN ON A.com Id=C c.i d;

CodePudding user response:

You can change the way of thinking to do, such as
Add a list of table b, name for the typeid, value is 1,
Add a column in table c, name for the typeid, value is 0,
The b and c two tables first union all the total table of d, then do associated with table a and total table d on Anderson, d=d.i d and a.t ypeid=which ypeid results,
Similar to SQL
-
 
Select *
From a
Left the join (
Select *, '1' as the typeid from b
Union all
Select *, '0' as the typeid from c) d on arjun yid=d.m yid2 and a.t ypeid=which ypeid
  • Related