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
 Where conditions
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

knocknaboula
Starting Member

3 Posts

Posted - 08/21/2014 :  05:53:40  Show Profile  Reply with Quote
WHERE
BCti.exchangeId = 13 OR BCti.exchangeId = 14 OR BCti.exchangeId = 18 OR BCti.exchangeId = 256 OR BCti.exchangeId = 395 OR BCti.exchangeId = 398 OR BCti.exchangeId = 405 OR BCti.exchangeId = 477 OR BCti.exchangeId = 496 OR BCti.exchangeId = 846 OR BCc.countryId = 37 )-- Canadian exchange id's
AND (BCct.companyTypeId = 1 OR BCct.companyTypeId = 4 OR BCct.companyTypeId = 13)-- 'A' or 'B'
AND (BCs.primaryFlag = 1 AND BCs.securitySubTypeId = 1)
AND (BCti.tradingItemStatusId = 15 OR BCti.tradingItemStatusId = 13 OR BCti.tradingItemStatusId = 10 OR BCti.tradingItemStatusId = 3 OR BCti.tradingItemStatusId = 5)
AND (BCti.tradingItemStatusId = 15 OR BCti.tradingItemStatusId = 13 OR BCti.tradingItemStatusId = 10 OR BCti.tradingItemStatusId = 3 OR BCti.tradingItemStatusId = 5)
AND BCti.primaryFlag = 1 AND (BCti.tradingItemStatusId = 15 OR BCti.tradingItemStatusId = 13 OR BCti.tradingItemStatusId = 10 OR BCti.tradingItemStatusId = 3 OR BCti.tradingItemStatusId = 5)


MY Problem is that some rows I need to return do not have a BCti.Primaryflag = 1 (the only options are 1 or 0). they do meet all the other where conditions.

I am not sure how I can incorporate them. Would this be done through a case statement? I need to keep the BCti.Primaryflag = 1 condition in there or I will gets multiple records for each company.

gbritton
Aged Yak Warrior

803 Posts

Posted - 08/21/2014 :  07:45:47  Show Profile  Reply with Quote
quote:
Originally posted by knocknaboula


MY Problem is that some rows I need to return do not have a BCti.Primaryflag = 1 (the only options are 1 or 0). they do meet all the other where conditions.

I am not sure how I can incorporate them. Would this be done through a case statement? I need to keep the BCti.Primaryflag = 1 condition in there or I will gets multiple records for each company.



These two requirements contradict each other and are not logically possible to achieve together. Please explain further what you are looking for.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 08/21/2014 :  08:14:25  Show Profile  Visit webfred's Homepage  Reply with Quote
How do you identify that "some rows"?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

knocknaboula
Starting Member

3 Posts

Posted - 08/21/2014 :  08:31:43  Show Profile  Reply with Quote
What is happening at the moment is that I am getting rows from BCTi where BCti.exchangeid not in (13,14,18,256,395,398,405,477,496,846) because they have a Primaryflag of 1 and they also meet the other where conditions. (They are being pulled in because they have Bcc.countryid = 37 which is correct).

So in affect what I want is where BCti.Primaryflag = 1 and exchangeid Not in (13,14,18,256,395,398,405,477,496,846) to then ignore the primary flag = 1 and return a row where the BCti.exchangeid is IN (13,14,18,256,395,398,405,477,496,846)
Go to Top of Page

gbritton
Aged Yak Warrior

803 Posts

Posted - 08/21/2014 :  08:45:51  Show Profile  Reply with Quote
so...why not this:


WHERE ((BCti.Primaryflag = 1 and exchangeid Not in (13,14,18,256,395,398,405,477,496,846))
   OR (exchangeid in (13,14,18,256,395,398,405,477,496,846)))
Go to Top of Page

knocknaboula
Starting Member

3 Posts

Posted - 08/21/2014 :  09:00:17  Show Profile  Reply with Quote
The problem is that where BCti.Primaryflag = 1 they may also be exchangeid is IN (13,14,18,256,395,398,405,477,496,846) and I only want to start looking at BCti.primaryflag = 0 where the above condition on primaryflag is not true but there are rows for this company in exchangeid = (13,14,18,256,395,398,405,477,496,846).
Go to Top of Page

gbritton
Aged Yak Warrior

803 Posts

Posted - 08/21/2014 :  09:06:27  Show Profile  Reply with Quote
quote:
Originally posted by knocknaboula

The problem is that where BCti.Primaryflag = 1 they may also be exchangeid is IN (13,14,18,256,395,398,405,477,496,846) and I only want to start looking at BCti.primaryflag = 0 where the above condition on primaryflag is not true but there are rows for this company in exchangeid = (13,14,18,256,395,398,405,477,496,846).



OK -- Add one more thing:


WHERE ((BCti.Primaryflag = 1 and exchangeid Not in (13,14,18,256,395,398,405,477,496,846))
   OR (BCti.Primaryflag = 0 and exchangeid in (13,14,18,256,395,398,405,477,496,846)))


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.11 seconds. Powered By: Snitz Forums 2000