Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get desired result from this query?
    primarykey
    data
    text
    <p>I have problem similar to my this question : <a href="https://stackoverflow.com/questions/16118306/sql-server-2008-case-statement-in-where-clause-not-working">sql server 2008 case statement in where clause not working</a></p> <p>I have same document,SR and event table.</p> <p>My document table structure is like this :</p> <pre><code>documentid int, documenttype nvarchar(50), relationid int, document image, docdate date </code></pre> <p>and SR table structure :</p> <pre><code>SRId int, CustomerId int, ( related to customer table) SRdetail, SRDate </code></pre> <p>and Event Table :</p> <pre><code>EventId int, SRId int, (related to SR table) Event, EventDate </code></pre> <p>I got all the rows properly with this query :</p> <pre><code>Select * from documents d left join SR s on d.relationid = s.SRId left join Events e on d.relationid = e.EventId </code></pre> <p>But I have to do filtration also. like I need to display all documents by customer.</p> <p>So I am performing query for this like this :</p> <pre><code> Select * from documents d left join SR s on d.relationid = s.SRId left join Events e on d.relationid = e.EventId where (s.CustomerId = 123 or e.SRId in (select SRId from SR where CustomerId = 123)) </code></pre> <p>But its not giving me proper output. its displaying some of the records of diff customer's events and that customer's SR. means its not filtering properly. </p> <p>I did try with 'and' instead of 'or' but with 'and' its displaying only some records.</p> <p>Am I wrong somewhere in query ?</p> <p>Can anyone please help me ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload