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.
| Author |
Topic |
|
SlinginParts
Starting Member
18 Posts |
Posted - 2012-06-25 : 14:08:28
|
[code]SELECT DISTINCT Attribute, ValueFROM ATRWHERE value like 'SC___'or value like 'SC__'and attribute like '&part&'and not attribute like '%brand%'and not attribute like '&type&'and not attribute like '&model&'and not attribute like '&make&'order by value asc[/code]ResultsAttribute ValueOther Part Number SC099Manufacturer Part Number SC288Model SC300Model ScampBrand ScionInterchange Part Number ScionMake ScionPart Brand ScionModel ScoutObviously I have some misunderstanding of the correct use of these functions. I have tried the not both after the and and before the like, neither worked.I'm trying to find an easy way to exude non-relevant results. I'm sure I need to be using some sort of variation of an if then statement but I'm very new to this with about 8 hours under my belt, so any help is appreciated.  |
|
|
SlinginParts
Starting Member
18 Posts |
Posted - 2012-06-25 : 14:14:13
|
| And to clarify, the resultsOther Part Number SC099Manufacturer Part Number SC288Are what I'm trying to get andModel SC300Model ScampBrand ScionInterchange Part Number ScionMake ScionPart Brand ScionModel ScoutI am trying to scrub. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
xhostx
Constraint Violating Yak Guru
277 Posts |
Posted - 2012-06-25 : 14:27:03
|
quote: Originally posted by SlinginParts
SELECT DISTINCT Attribute, ValueFROM ATRWHERE value like 'SC___'or value like 'SC__'and attribute like '&part&'and not attribute like '%brand%'and not attribute like '&type&'and not attribute like '&model&'and not attribute like '&make&'order by value asc ResultsAttribute ValueOther Part Number SC099Manufacturer Part Number SC288Model SC300Model ScampBrand ScionInterchange Part Number ScionMake ScionPart Brand ScionModel ScoutObviously I have some misunderstanding of the correct use of these functions. I have tried the not both after the and and before the like, neither worked.I'm trying to find an easy way to exude non-relevant results. I'm sure I need to be using some sort of variation of an if then statement but I'm very new to this with about 8 hours under my belt, so any help is appreciated. 
Distinct ==> will only bring UNIQUE values from your table (if there's any duplicates i will not appear part of result)Underscores (_) will act like any wild card to replace any character in the third, fourth or fifth position in your case...Percentage (%) usually represents a string of characters (it could be any number, character, or nothing sometimes '').Order by Columns name ASC= ASCENDING.\Good luckkml |
 |
|
|
SlinginParts
Starting Member
18 Posts |
Posted - 2012-06-25 : 16:09:42
|
| OK thank you guys. First of all, the use of & and % is embarrassing. Here is what solved it for me. I'm sure this is a terrible way to do it, but until I get better here's what worked for anyone that wants to learn from my mistakes!SELECT DISTINCT Attribute, ValueFROM ATRWHERE attribute like '%part%'and (value like 'SC__' or value like 'SC___')/*value like 'SC-___' or value like 'SC-__' or */and not (attribute like '%brand%' or attribute like '%type' or attribute like '%model%' or attribute like '%make%')and not value like '%scion%'order by value asc |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
SlinginParts
Starting Member
18 Posts |
Posted - 2012-06-25 : 18:03:48
|
Thank you. I'm working on a monster query that probably goes beyond the scope of newby posts so I'm going to put together more documentation and post it to the appropriate forum. I see you're all over the place here so I'm sure I'll see you in there.Thanks a lot! This is a lot to take in |
 |
|
|
|
|
|
|
|