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
 Database Design and Application Architecture
 SELECT HELP

Author  Topic 

mcr888
Starting Member

3 Posts

Posted - 2007-10-26 : 13:18:20
I have a view that I am selecting from. At the time that I am selecting from this view, I would like to select all records that do not have a value in TypeID AND those records that are not equal to a particular TypeID / DetailID combination. (for instance not=1 and not=1 in the example, second and third rows) but also, the catch here is, I only need to show one of those records that match the TypeID <> 1 and DetailID <> 1 ..not both. What would my select be? How would I limit those other records. Any help would be greatly appreciated. I have been struggling with this for almost two days now. If you need any other info on this, please let me know and I would try to be as concise as possible. Thanks in advance to anyone that can help.

DetailID TypeID KeyID
1 1 3
2 1 3
1 2 3
NULL NULL 4

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-10-26 : 23:35:24
Taking your example, you say you want to show only one of the records where TypeID <> 1 OR KeyID <> 1 - which one? Do you not care or do you want a particular one of the two?
Go to Top of Page

mcr888
Starting Member

3 Posts

Posted - 2007-10-29 : 11:58:34
Thank you very much for the response. In this case, I may just need to show any one as a reference point to the user in a grid, but now I am not sure that will be enough to solve my problem. It may be more complicated as I look through this.

All three of these records are essentially the same in the view that I have created. From my KeyID through the other columns that are not shown here, are the contact information for a customer. In this case it is customer #3. The only difference in the records is that they have a different DetailID and TypeID combination. What I need to select and show is all records that match the DetailID = 1 AND TypeID = 1 but if a different customer record has a DetailID and TypeID combination NOT 1 and 1, (and does not have an exact 1 and 1 record at all, but has other combinations) I need to show that customer also. meaning.....I need to see only one record for that customer that matches the 1 and 1 criteria and any other single record for other customers that do not have an exact 1 and 1 match. I hope that makes sence. If you have any suggestions, I do appreciate it very much. Thanks.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-10-29 : 12:50:59
too many words

What the result set you want look like



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

mcr888
Starting Member

3 Posts

Posted - 2007-10-29 : 14:44:00
Thanks for the response. I do appreciate it. I want to see only one record for any of the Customers (indicated by the keyID) IF the customer does not have a (DetailID = 1 AND TypeID = 1) record. For instance, he may have other many combinations of DetailID = ? AND TypeID = ? but if he does not already have 1 and 1 I just need to show any one record, does not matter which one.

Thank you again.
Go to Top of Page
   

- Advertisement -