E
eastweast
Unregistered / Unconfirmed
GUEST, unregistred user!
新接手一數據庫程序,在Client端使用了很多類似下面的T-SQL語句:
Select IsNull(B.ICode,A.ICode) As ICode,BQty From (Select ItemCode,DifCode=Case When Upper(Right(RTrim(ICode),3))='-BB' Then Left(ICode,len(ICode)-3) Else ICode End,BQty From Select distinct IsNull(E.ICode,B.ICode) As ICode,IsNull(A.BQty*D.BQty,A.BQty) As BQty From BP_Item A Inner Join Item B On A.ItemID=B.ID Left Join Bom C On B.ID=C.ItemID Left Join BomD D On C.ID=D.BomID Left Join Item E On D.ItemID=E.ID Where A.ID In (Select A.ID From Bom A Inner Join item B On A.IID=B.ID Where B.ICode='abcdef') And A.ID In (Select ID from PIDs('abceef','檢查'))) A) A Left Join (Select D.Code from OrderS a Left Join
CBom B On A.CBID=B.ID left Join CB_d C On B.ID=C.BomID left join item d on c.cid=d.id where a.sno='abcd0690095') B On A.DifCode=B.Code
以上語句要想搞明白是什麼意思,需要將以上T-sql代碼進行格式化為類似下面的形式:
Select IsNull(B.ICode,A.ICode) As ICode,BQty
From
(Select ItemCode,DifCode=Case When Upper(Right(RTrim(ICode),3))='-BB' Then Left(ICode,len(ICode)-3) Else ICode End,BQty From
(Select distinct IsNull(E.ICode,B.ICode) As ICode,IsNull(A.BQty*D.BQty,A.BQty) As BQty
From
BP_Item A Inner Join
Item B On A.ItemID=B.ID Left Join
Bom C On B.ID=C.ItemID Left Join
BomD D On C.ID=D.BomID Left Join
Item E On D.ItemID=E.ID
Where A.ID In (Select A.ID From Bom A Inner Join item B On A.IID=B.ID Where B.ICode='abcdef') And A.ID In (Select ID from PIDs('abceef','檢查'))) A
) A
Left Join
(Select D.Code
from
OrderS a Left Join
CBom B On A.CBID=B.ID left Join
CB_d C On B.ID=C.BomID left join
item d on c.cid=d.id
where a.sno='abcd0690095'
) B
On A.DifCode=B.Code
由於程序中使用了太多的這種雜亂的t-sql所以造成維護很麻煩.因此想寫一程序,經原始t-sql進行格式化.請各位不吝賜教.
此處不討論這些代碼放在客戶端的弊端.
使用過SourceFormatX這個軟件,但是不支持sql.
Select IsNull(B.ICode,A.ICode) As ICode,BQty From (Select ItemCode,DifCode=Case When Upper(Right(RTrim(ICode),3))='-BB' Then Left(ICode,len(ICode)-3) Else ICode End,BQty From Select distinct IsNull(E.ICode,B.ICode) As ICode,IsNull(A.BQty*D.BQty,A.BQty) As BQty From BP_Item A Inner Join Item B On A.ItemID=B.ID Left Join Bom C On B.ID=C.ItemID Left Join BomD D On C.ID=D.BomID Left Join Item E On D.ItemID=E.ID Where A.ID In (Select A.ID From Bom A Inner Join item B On A.IID=B.ID Where B.ICode='abcdef') And A.ID In (Select ID from PIDs('abceef','檢查'))) A) A Left Join (Select D.Code from OrderS a Left Join
CBom B On A.CBID=B.ID left Join CB_d C On B.ID=C.BomID left join item d on c.cid=d.id where a.sno='abcd0690095') B On A.DifCode=B.Code
以上語句要想搞明白是什麼意思,需要將以上T-sql代碼進行格式化為類似下面的形式:
Select IsNull(B.ICode,A.ICode) As ICode,BQty
From
(Select ItemCode,DifCode=Case When Upper(Right(RTrim(ICode),3))='-BB' Then Left(ICode,len(ICode)-3) Else ICode End,BQty From
(Select distinct IsNull(E.ICode,B.ICode) As ICode,IsNull(A.BQty*D.BQty,A.BQty) As BQty
From
BP_Item A Inner Join
Item B On A.ItemID=B.ID Left Join
Bom C On B.ID=C.ItemID Left Join
BomD D On C.ID=D.BomID Left Join
Item E On D.ItemID=E.ID
Where A.ID In (Select A.ID From Bom A Inner Join item B On A.IID=B.ID Where B.ICode='abcdef') And A.ID In (Select ID from PIDs('abceef','檢查'))) A
) A
Left Join
(Select D.Code
from
OrderS a Left Join
CBom B On A.CBID=B.ID left Join
CB_d C On B.ID=C.BomID left join
item d on c.cid=d.id
where a.sno='abcd0690095'
) B
On A.DifCode=B.Code
由於程序中使用了太多的這種雜亂的t-sql所以造成維護很麻煩.因此想寫一程序,經原始t-sql進行格式化.請各位不吝賜教.
此處不討論這些代碼放在客戶端的弊端.
使用過SourceFormatX這個軟件,但是不支持sql.