| Author |
Topic |
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-29 : 14:09:10
|
| I need some serious help with this query...SELECT *FROM dbo.wce_contactWHERE (Mail1Date IS NOT NULL)AND (Mail2Date IS NULL)AND (Mail3Date IS NULL)AND (Mail4Date IS NULL)AND (Mail5Date IS NULL)AND (Mail6Date IS NULL)AND (Mail7Date IS NULL)AND (Mail8Date IS NULL)AND (Mail9Date IS NULL)AND (Mail10Date IS NULL)AND (Mail11Date IS NULL)AND (Mail12Date IS NULL)AND (Mail14Date IS NULL)AND (Mail15Date IS NULL)AND (Mail16Date IS NULL)or(IDStatus LIKE '')or (NOT (Task LIKE '%x%'))or (ExpressEmail LIKE '%@%')or (WebSite NOT LIKE '')or (Unsubscribe = 0)or (Artwork LIKE '')Basically the parts in red work best when they use the 'or' criteria. My problem.I run the query together black+red and get a different result than expected. Is there a way of saying 'do the black part first and its an imperative that the red part follows those rules on the black part of the query?' eg:IDStatus must be LIKE '' when running the black part of the queryand expressemail must be like '%@%' on the black part of the query but not on red part of the query. So it doesnt matter that the expressemail must have idstatus like '' whilst having an @Hope it makes sense?? |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-29 : 14:12:59
|
| Don't you want BlackPartGoesHere AND (RedPartGoesHere).What do you mean it works best when using OR? Do you get the correct results?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 14:13:09
|
| You may make more sense if you illustrate what you are looking for with the help of some sample data. |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-29 : 14:23:48
|
| "What do you mean it works best when using OR? Do you get the correct results?" when using or it is not looking at the records in the way i want it to. hope i explain it better belowor(IDStatus LIKE '')or (NOT (Task LIKE '%x%'))or (ExpressEmail LIKE '%@%')or (WebSite NOT LIKE '')or (Unsubscribe = 0)or (Artwork LIKE '')by using the 'or part' i mean that this criteria doenst want to be AND. eg a contact where idstatus not like '' but the expressemail like '%@%'or even simplier - i am trying to find a record where the website field is not blank and the idstatus field is not blank and the task field doesnt contain 'x' and the expressemail field contains '@' and artwork is not blank and unsubscribe is equal to onebut sometimes a record can match the first two lines of the red part and not the rest, but i still want to bring them up in the results. At the same time the black part is a definate must match criteria. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 14:28:43
|
quote: Originally posted by Topaz "What do you mean it works best when using OR? Do you get the correct results?" when using or it is not looking at the records in the way i want it to. hope i explain it better belowor(IDStatus LIKE '')or (NOT (Task LIKE '%x%'))or (ExpressEmail LIKE '%@%')or (WebSite NOT LIKE '')or (Unsubscribe = 0)or (Artwork LIKE '')by using the 'or part' i mean that this criteria doenst want to be AND. eg a contact where idstatus not like '' but the expressemail like '%@%'or even simplier - i am trying to find a record where the website field is not blank and the idstatus field is not blank and the task field doesnt contain 'x' and the expressemail field contains '@' and artwork is not blank and unsubscribe is equal to onebut sometimes a record can match the first two lines of the red part and not the rest, but i still want to bring them up in the results. At the same time the black part is a definate must match criteria.
May be this is what you wantSELECT *FROM dbo.wce_contactWHERE (Mail1Date IS NOT NULL)AND (Mail2Date IS NULL)AND (Mail3Date IS NULL)AND (Mail4Date IS NULL)AND (Mail5Date IS NULL)AND (Mail6Date IS NULL)AND (Mail7Date IS NULL)AND (Mail8Date IS NULL)AND (Mail9Date IS NULL)AND (Mail10Date IS NULL)AND (Mail11Date IS NULL)AND (Mail12Date IS NULL)AND (Mail14Date IS NULL)AND (Mail15Date IS NULL)AND (Mail16Date IS NULL)AND ((IDStatus LIKE '')or (NOT (Task LIKE '%x%'))or (ExpressEmail LIKE '%@%')or (WebSite NOT LIKE '')or (Unsubscribe = 0)or (Artwork LIKE '')) |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-29 : 14:39:01
|
| that just seems to bring up the results where the red part matches our database and then does the black bit aswell. hth? im trying to find records in our database that MUST match the black part and can match ANY line of the red part as long as it matches the black part. becasue at the moment it looks like it is doing the black and then doing the red parts seperately |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 14:46:23
|
quote: Originally posted by Topaz that just seems to bring up the results where the red part matches our database and then does the black bit aswell. hth? im trying to find records in our database that MUST match the black part and can match ANY line of the red part as long as it matches the black part. becasue at the moment it looks like it is doing the black and then doing the red parts seperately
Is nt that what the query i posted do?It returns only those records that matches all of the black part and also atleast any one of the red part. If you are still not getting expected results you need to show us with some sample data what you're expecting. |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-29 : 14:53:31
|
| ill have to post some sample data up tomorrow...not at work right now.for instance that query brings up records that has something in the idstatus (so not '') or has something in the expressemail field where it doesnt have an '@'thanks for your help so far! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 15:10:54
|
quote: Originally posted by Topaz ill have to post some sample data up tomorrow...not at work right now.for instance that query brings up records that has something in the idstatus (so not '') or has something in the expressemail field where it doesnt have an '@'thanks for your help so far!
It will definitely be retrieved if record matches any other of condition in red like Unsubscribe=0 or Artwork like ''... Do you mean you want to make the above two conditions mandatory?ie. idstatus LIKE '' and (ExpressEmail LIKE '%@%')? |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-29 : 16:42:48
|
| in fact this might be easier to understand. I need a query that will find records that match any line that is in red but at the same time it must match the black part of the qry exactly. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-29 : 23:38:20
|
quote: Originally posted by Topaz in fact this might be easier to understand. I need a query that will find records that match any line that is in red but at the same time it must match the black part of the qry exactly.
Thats same as the one i provided.The AND conditions ensure all of black part is matched and ORs inside red part ensure any of the condition is matched.b.w what's preventing you from posting some sample data of what you expect? that would have made it much esier for people trying to hel[ you out. If you need more help on this, post some sample data for the output you're expecting. |
 |
|
|
Topaz
Posting Yak Master
199 Posts |
Posted - 2008-05-30 : 04:50:29
|
| [URL=http://www.bigupload.com/files/61PF7B4VFB/Sample.xls.zip.html]Sample.Xls.Zip by Bigupload.Com[/URL]Please find some sample data (link) that might help you guys understand whats going on. These are the results that get displayed when i run this query:SELECT *FROM dbo.wce_contactWHERE (Mail1Date IS NOT NULL)AND (Mail2Date IS NULL)AND (Mail3Date IS NULL)AND (Mail4Date IS NULL)AND (Mail5Date IS NULL)AND (Mail6Date IS NULL)AND (Mail7Date IS NULL)AND (Mail8Date IS NULL)AND (Mail9Date IS NULL)AND (Mail10Date IS NULL)AND (Mail11Date IS NULL)AND (Mail12Date IS NULL)AND (Mail14Date IS NULL)AND (Mail15Date IS NULL)AND (Mail16Date IS NULL)AND ((IDStatus LIKE '')or (NOT (Task LIKE '%x%'))or (ExpressEmail LIKE '%@%')or (WebSite NOT LIKE '')or (Unsubscribe = 0)or (Artwork LIKE '')) |
 |
|
|
|