Author |
Topic |
bcarney
Starting Member
7 Posts |
Posted - 2013-05-21 : 09:14:17
|
I have a table with multiple columns that I am trying to build a query that will evaluate two of the columns and return only the data that does not meet specific parametersName |Status | Ageing | Last_changeA | set | 10 | 12/12/13B | locked | 12 | 12/12/13C | (null) | 10 | 12/12/13D | unlocked| 99 | 12/12/13E | Set | (null) | 12/12/13In the above example data, I would like to evaluate the "Status" and "Ageing" Column an return any combination that does have a Status of "Set" and/or Ageing greater than "10" or null. So "A" would not be returned but B through E would be returned.Thanks Brian |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-21 : 10:09:27
|
Something like this?SELECT * FROM tblWHERE ISNULL(Status,'') <> 'set'OR ageing > 10 OR ageing IS NULL |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-22 : 00:38:55
|
Tell us how you think below record will be returned?C | (null) | 10 | 12/12/13it has Status value as null and also its Ageing is not greater than 10------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
bcarney
Starting Member
7 Posts |
Posted - 2013-05-22 : 14:43:19
|
Thanks everyone I've been dealing with a PC problem since yesterday. Some addtional information I for got to mention, I am using MS SQL 2008R2. Visakh16C | (null) | 10 | 12/12/13Actualy rows B,C,D,E should all returnShould return due to the Null in the second field. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-05-22 : 14:52:35
|
quote: Originally posted by bcarney I have a table with multiple columns that I am trying to build a query that will evaluate two of the columns and return only the data that does not meet specific parametersName |Status | Ageing | Last_changeA | set | 10 | 12/12/13B | locked | 12 | 12/12/13C | (null) | 10 | 12/12/13D | unlocked| 99 | 12/12/13E | Set | (null) | 12/12/13In the above example data, I would like to evaluate the "Status" and "Ageing" Column an return any combination that does have a Status of "Set" and/or Ageing greater than "10" or null. So "A" would not be returned but B through E would be returned.Thanks Brian
When I posted my first reply to your question, I thought you had a "not" in there as in "In the above example data, I would like to evaluate the "Status" and "Ageing" Column an return any combination that does not have a Status of "Set" and/or Ageing greater than "10" or null. So "A" would not be returned but B through E would be returned."Doesn't the code I posted not work for you? If it does not, can you post whether the results should be return or not for the following cases?Status Ageingnull 5null 10null 15null nullABCD 5ABCD 10ABCD 15ABCD nullset 5set 10set 15set null |
|
|
bcarney
Starting Member
7 Posts |
Posted - 2013-05-22 : 15:20:29
|
These should return... (I'm not a programer in case you had not determined it. LOL) These should all be returned:Status Ageingnull 5null 10null 15null nullABCD 15ABCD nullset 15set null |
|
|
bcarney
Starting Member
7 Posts |
Posted - 2013-05-22 : 15:20:37
|
These should return... (I'm not a programer in case you had not determined it. LOL) These should all be returned:Status Ageingnull 5null 10null 15null nullABCD 15ABCD nullset 15set null |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-23 : 00:33:47
|
This is not as per your original explanantion as I can still see records with Status value <> 'Set' and still you getting it in outputAnyways if we assume this is really what you want, I think you can use thisSELECT * FROM tblWHERE Status IS NULLOR (Status = 'Set' AND (Ageing >10 OR Ageing IS NULL)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|