Thursday, April 19, 2012

SQL Datetime Not Equal To Is Not Working

I have a database consisting of a Customer, Product, and Transaction table.

I'm trying to write an SQL statement to list all customers' names and SSN's for those customers who have made no transaction in the year 2000.

The TransactionDate column in the Transaction table is a Date/Time data type (e.g. 2000-12-18 00:00:00).

This is the SQL code I've written:

SELECT DISTINCT CustomerName, Customer.CustomerSSN 
FROM Customer, Transaction
WHERE Customer.CustomerSSN=Transaction.CustomerSSN
AND YEAR(TransactionDate)<>2000;

The not equal to symbol (<>) seems to not be working for some reason. When I change it to an equal sign, it does return the correct result...

Any advice is appreciated.

No comments:

Post a Comment