摆脱{

时间:2014-12-01 17:17:14

标签: mysql sql

SELECT DISTINCT 
    l.State, e.CorpID, e.LocID, tl.State AS 'Transferred From State',       
    e.TransferFromLocID AS 'Transferred From Location', 
    e.FirstName, e.LastName, e.SSN, 
    CONVERT(CHAR(10), e.CurrentBeginDate, 101) AS 'Start Date', 
    CONVERT(CHAR(10), e.BeginDate, 101) AS 'Begin Date', 
    CONVERT(CHAR(10), e.TermDate1, 101) AS 'Term Date', 
    (ISNULL(w.EligibleCode1, '') + ' ' + ISNULL(w.EligibleCode2, '') + ' ' + ISNULL(w.EligibleCode3, '') + ' ' + ISNULL(w.EligibleCode4, '') + ' ' + ISNULL(w.EligibleCode5, '')) AS 'Eligibility Code',   
    w.Disqualified, dcrs.StatusDescription AS 'DCR Status', 
    vt.TrackingCodes,      
    CONVERT(CHAR(10), w.DocRequestDate, 101) AS 'Doc Request Date',
    (CASE 
        WHEN w.RequestComplete = '0' 
          THEN  
            (CASE 
                WHEN w.EligibleCode1 IN ('I','A','G') 
                  THEN
                    (CASE 
                       WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11') 
                         THEN '11'
                         ELSE '' 
                     END)
                WHEN w.EligibleCode1 IN ('B','J','Z') 
                  THEN
                    (CASE 
                        WHEN (w.DocRecvd1 NOT IN ('4','11') AND w.DocRecvd2 NOT IN('4','11')) 
                          THEN '4, 11' 
                        WHEN (w.DocRecvd1 <> '4' AND w.DocRecvd2 <> '4')   
                          THEN '4'
                        WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11') 
                          THEN '11'
                        ELSE '' 
                     END)
                WHEN w.EligibleCode1 IN ('C') 
                  THEN
                    (CASE WHEN (w.DocRecvd1 NOT IN ('6','11') AND w.DocRecvd2 NOT IN('6','11')) THEN '6, 11' 
                    WHEN (w.DocRecvd1 <> '6' AND w.DocRecvd2 <> '6') THEN '6'
                    WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11') THEN '11'
                    ELSE '' END)
                WHEN w.EligibleCode1 IN ('D','F') THEN
                    (CASE WHEN (w.DocRecvd1 NOT IN ('1','9') AND w.DocRecvd2 NOT IN('1','9')) THEN '1, 9' 
                    WHEN (w.DocRecvd1 <> '1' AND w.DocRecvd2 <> '1') THEN '1'
                    WHEN (w.DocRecvd1 <> '9' AND w.DocRecvd2 <> '9') THEN '9'
                    ELSE '' END)
                WHEN w.EligibleCode1 IN ('E') THEN
                    (CASE WHEN (w.DocRecvd1 NOT IN ('5','11') AND w.DocRecvd2 NOT IN('5','11')) THEN '5, 11' 
                    WHEN (w.DocRecvd1 <> '5' AND w.DocRecvd2 <> '5') THEN '5'
                    WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11') THEN '11'
                    ELSE '' END)
                WHEN w.EligibleCode1 IN ('H') THEN
                    (CASE WHEN (w.DocRecvd1 NOT IN ('10','11') AND w.DocRecvd2 NOT IN('10','11')) THEN '10, 11' 
                    WHEN (w.DocRecvd1 <> '10' AND w.DocRecvd2 <> '10') THEN '10'
                    WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11') THEN '11'
                    ELSE '' END)
                WHEN w.EligibleCode1 IN ('W','Y') THEN
                    (CASE WHEN (w.DocRecvd1 NOT IN ('4','11','13') AND w.DocRecvd2 NOT IN('4','11','13') AND w.DocRecvd3 NOT IN('4','11','13')) THEN '4, 11, 13' 
                    WHEN (w.DocRecvd1 NOT IN ('4','11') AND w.DocRecvd2 NOT IN('4','11') AND w.DocRecvd3 NOT IN('4','11')) THEN '4, 11'
                    WHEN (w.DocRecvd1 NOT IN ('4','13') AND w.DocRecvd2 NOT IN('4','13') AND w.DocRecvd3 NOT IN('4','13')) THEN '4, 13'
                    WHEN (w.DocRecvd1 NOT IN ('11','13') AND w.DocRecvd2 NOT IN('11','13') AND w.DocRecvd3 NOT IN('11','13')) THEN '11, 13'
                    WHEN (w.DocRecvd1 <> '4' AND w.DocRecvd2 <> '4' AND w.DocRecvd3 <> '4') THEN '4'
                    WHEN (w.DocRecvd1 <> '11' AND w.DocRecvd2 <> '11' AND w.DocRecvd3 <> '11') THEN '11'
                    WHEN (w.DocRecvd1 <> '13' AND w.DocRecvd2 <> '13' AND w.DocRecvd3 <> '13') THEN '13'
                    ELSE '' END)
            ELSE '' END)    
        ELSE '' END) AS 'Docs Needed',
        (CAST(w.DocRecvd1 AS VARCHAR(5)) + ',' + CAST(w.DocRecvd2 AS VARCHAR(5)) + ',' + CAST(w.DocRecvd3 AS VARCHAR(5))) AS 'Docs Received'
FROM 
    Employee e
LEFT JOIN 
    Location l ON (l.CorpID = e.CorpID AND l.LocID = e.LocID)
LEFT JOIN 
    Location tl ON (tl.CorpID = e.CorpID AND tl.LocID = e.TransferFromLocID)
INNER JOIN 
    EmpWOTC w ON w.Wormnumber = e.Wormnumber
LEFT JOIN 
    EmpTrackingCode tc ON tc.WormNumber = e.Wormnumber
INNER JOIN 
    TrackCd t ON t.TrackingCodeID = tc.TrackingCodeID
INNER JOIN 
    vw_TrackingCodes vt ON vt.WormNumber = e.WormNumber
LEFT JOIN 
    EmpWOTCDCRAddress dcra ON dcra.Wormnumber = e.Wormnumber
INNER JOIN 
    EmpWOTCDCRStatus dcrs ON dcrs.StatusID = dcra.StatusID
WHERE 
    w.CertRecvdDate IS NULL
    AND (e.BeginDate BETWEEN '1/1/2010' AND GETDATE())
    AND w.ICFIssueDate IS NOT NULL
    AND w.eligible = 1
    AND vt.TrackingCodes Like '%HDF%'
    AND vt.TrackingCodes NOT Like '%^%'
    AND vt.TrackingCodes NOT Like '%OSB%'
    AND vt.TrackingCodes NOT Like '%N%'
    AND vt.TrackingCodes NOT Like '%S%'
    AND w.Disqualified = 0
ORDER BY 
    l.State, e.SSN

我有这段代码,但是跟踪代码列的输出是{xx} {yy},所以如何获得相同的答案,而没有{}和它们之间的空格?我将这些数据带入Excel以进行更多操作并在该操作上运行更多代码,但基本上我需要能够对我所拥有的结果执行状态搜索。然后我想搜索基于这些状态的不同跟踪代码以及那些{我无法让Excel找到它们。当我删除它们然后分开它们就可以了。

1 个答案:

答案 0 :(得分:3)

如果您只需删除括号,则可以使用REPLACE()

REPLACE(REPLACE(REPLACE(vt.TrackingCodes,'}{',' '),'{',''),'}','') AS TrackingCodes

使用3 REPLACE()而不是2,以便在集合之间出现唯一的空格。