SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Limiting by not equal to
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tranquilraven
Starting Member

19 Posts

Posted - 06/07/2012 :  14:53:03  Show Profile  Reply with Quote
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

Edited by - tranquilraven on 06/07/2012 16:23:39

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 06/07/2012 :  15:09:43  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3857 Posts

Posted - 06/07/2012 :  15:21:00  Show Profile  Reply with Quote
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
Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

3857 Posts

Posted - 06/07/2012 :  16:50:18  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 06/07/2012 :  16:50:45  Show Profile  Visit webfred's Homepage  Reply with Quote
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 - 06/07/2012 :  17:09:15  Show Profile  Reply with Quote

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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000