Home > database >  How SQL server actually a column of data in the query to continue using cyclic query
How SQL server actually a column of data in the query to continue using cyclic query

Time:09-23

this is the query according to table A

how to add A column in A table (B) is based on A table in the areaId
Check parentId values in table B and then found his grandparents (need is the highest-level cycle to parentId==null or parentId==02)

CodePudding user response:

Table A query:
The SELECT e.e mpName, b.O rderNum, Arthur c. ustName, b.O rderMoney from SaleOrderHedTB a
Left the join SaleOrderDetTB b on a.S aleOrderNo=b.S aleOrderNo
Left the join EmployeeTB e on a.S Mr. Eller=e.E mpID
Left the join CustomerMasterTB c on a.C ustId=Arthur c. ustId
Where 1=1
And a.O rderDate BETWEEN '2018-09-01' and '2018-09-04 s'
And a.A uditFlag=1

CodePudding user response:

The
refer to the original poster weixin_42127476 response:


To use with statement, you must first in table B, to find his father's father,,,,

CodePudding user response:

According to the data you provide, I think you take b table parentId top two is the most simple way

CodePudding user response:

reference wildwolv reply: 3/f
according to the data you provided, I think you take b table parentId top two is the simplest approach
then case judging the when, if the first two is 02, then 02 else null
  • Related