如何为(CC / FGLIC / 2018/001)创建Sql字符串格式

时间:2018-02-03 06:57:16

标签: sql sql-server

我想根据字符串格式( 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%'

enter image description here

1 个答案:

答案 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 '%/%/%';