Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Limiting by not equal to

Author  Topic 

tranquilraven
Starting Member

19 Posts

Posted - 2012-06-07 : 14:53:03
UPDATE: The values seem to be Y and NULL. It isn't a boolean value after all, it is a varchar. Now I really don't understand why my query won't run.

I am trying to limit the records based on whether or not the payment has declined. This query does not throw an error but does nto pull any records even though I know there are records that don't have the paymentdeclined set to Y. The paymentdeclined is set as a boolean in the database. Can anyone please supply a second set of eyes and tell me what I am screwing up.

Thanks so much


SELECT OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM Orders
WHERE PaymentDeclined <> 'Y'
ORDER BY OrderDate DESC

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2012-06-07 : 15:09:43
SQL doesn't have boolean values, only values that the user can interpret as true or false.
Do SELECT DISTINCT PaymentDeclined FROM Orders, and see what the values are. That's what you'll have to use
in your query.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-07 : 15:21:00
[code]SELECT OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM Orders
WHERE PaymentDeclined = CAST(0 AS BIT)
ORDER BY OrderDate DESC
[/code]
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2012-06-07 : 16:50:18
Probably becuase any value comapred to NULL equals UNKNOWN. Try this:
SELECT OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM Orders
WHERE PaymentDeclined IS NULL
ORDER BY OrderDate DESC
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-06-07 : 16:50:45
WHERE isnull(PaymentDeclined,'') <> 'Y'


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

tranquilraven
Starting Member

19 Posts

Posted - 2012-06-07 : 17:09:15

You Rock Lamprey, and thank you for the explanation as well.

quote:
Originally posted by Lamprey

Probably becuase any value comapred to NULL equals UNKNOWN. Try this:
SELECT OrderDate AS 'Order Date',
PaymentAmount AS 'Total Payments',
TotalShippingCost AS 'Shipping Received',
SalesTax1 AS 'Sales Tax Received',
PaymentDeclined AS ' Payment Declined'
FROM Orders
WHERE PaymentDeclined IS NULL
ORDER BY OrderDate DESC


Go to Top of Page
   

- Advertisement -