1

I am trying to retrieve some information from our database. Specifically serial numbers. I need to utilize the SUBSTRING function to do this however, I am really stuck. I need to get all serial numbers who's 13th digit is a 0 and 14th digit is a 1. Since the serial numbers can change at anytime I thought checking the CustomerLotID columns for a 13th digit 0 and 14th digit 1 would be the best option however I am having some issues doing this. Please note that the 1, 2, '2/28/2017' after the select statements are for testing only.

SELECT  
    1, 2, '2/28/2017', '06:00', TX.OperationID, FriendlyName,
    COUNT(DISTINCT(CustomerLotID)) AS SerialNumber
FROM    
    fsWIPTxHist Tx 
INNER JOIN 
    FactoryServerMES.dbo.fsOperation O ON TX.OperationID = O.OperationID
WHERE   
    customerlotid = SUBSTRING('0',13,1) --<> '5D25984G14120%'
    AND (TX.DateCreated BETWEEN '2/28/2017 10:00:00' AND '2/28/2017 10:59:59') 
    AND (Status = 'Avail')
    AND TX.OperationID IN (3100) 
GROUP BY 
    TX.OperationID, FriendlyName
2
  • 3
    WHERE SubString(customerlotid, 13, 2) = '01' doesn't work for you? Did you consider reading the documentation for SubString? Commented Mar 2, 2017 at 1:23
  • I did read the documentation on MSDN. However, I may have misunderstood the syntax. Sorry if I wasted time for simple stuff. I think what confused me was the expression part of it. Thank you kindly for your help. Commented Mar 2, 2017 at 2:29

1 Answer 1

2

Try this:

WHERE SUBSTRING(customerlotid ,13,2) = '01'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.