我想根据字符串格式( ABCD / 2018/001 )获取详细信息, (的 ABCDEFG / 2018/00002 )。我不知道在斜线之前有多少文本。
SELECT cp.CaseID, cp.BillNo, ca.CaseNo, ca.CaseName, ISNULL(cp.Balance,0) AS BalanceAmount, ISNULL(cp.TotalAmount,0) AS PaidAmount
FROM Cases ca
LEFT JOIN CasePayment cp ON cp.CaseID=ca.ID
WHERE cp.BillNo LIKE '%ABC/2018/0001%'
答案 0 :(得分:1)
As i can see, slash(/) is occurring two times in BillNo column, to do this you can use the like expression in where
clause. For eg: LIKE '%/%/%'
Please try the below SQL:
SELECT cp.CaseID, cp.BillNo, ca.CaseNo, ca.CaseName, ISNULL(cp.Balance,0) AS BalanceAmount, ISNULL(cp.TotalAmount,0) AS PaidAmount
FROM Cases ca
LEFT JOIN CasePayment cp ON cp.CaseID=ca.ID
WHERE cp.BillNo LIKE '%/%/%';