I’m fairly new to coding in T-SQL and have run into an issue I have yet to find and answer. I was hoping the experts here and tell me where I have gone wrong.
I am trying to compare 2 columns of serial numbers with a not in statement and it works perfectly if there are only numbers in the columns but if there is a letter in the serial number it just kicks back all the records instead of just the records that are not in the second table. Below is my query I hope someone can point out what I have done wrong. Thank you in advance.
@Transaction varchar (50)
AS
SET NOCOUNT ON;
SELECT transaction, equiptype, serialnum
FROM table1
WHERE ( serialnum NOT IN
(SELECT serial_num
FROM table2 ) AND transaction = @Transaction)
P.S. a is my transaction number I am filtering the record by
table1-
[transaction] [equiptype] [serialnum]
12345678 12 56742
12345678 11 87529
12345678 8 46259
87654321 8 the143
87654321 10 the527
87654321 11 u3765
table2-
[transdate] [transaction] [user] [equiptype] [serial_num] [status]
7/28/11 12345678 test 12 56742 NewStock
7/28/11 12345678 test 11 87529 NewStock
7/28/11 87654321 test 11 u3765 NewStock
7/28/11 87654321 test 10 the527 NewStock
Based off this data transaction 12345678 will only return the last record with serialnum 46259 and that works fine but if I try to do the same with transaction 87654321 it will return all records as if the NOT IN statment failed to run instead of serial number the143.
Maybe it’s the from Server Collation. Please try