Solved

SQL Where Clause Help

Posted on 2013-10-25
3
209 Views
Last Modified: 2013-11-08
I have the following code and I do not know how to modify it for the following..... I need to add a where clause for the following.

Where Referral_Source is NOT NULL OR BLANK/EMPTY.




SELECT NewBusinessHeader.Exec_Name, NewBusinessHeader.Client_Last_Name, NewBusinessLineItem.EffectiveDate, NewBusinessLineItem.Carrier, NewBusinessLineItem.LineOfBusiness, NewBusinessLineItem.SoldPremium, NewBusinessLineItem.Sold, NewBusinessHeader.Referral_Source,NewBusinessHeader.Branch,NewBusinessHeader.Dept,NewBusinessHeader.Customer_Number as Agency_Rev,NewBusinessHeader.Process_Complete_Date,NewBusinessHeader.Group_Submission_Number

FROM NewBusinessHeader INNER JOIN NewBusinessLineItem ON NewBusinessHeader.NBHeaderID = NewBusinessLineItem.NBHeaderID

WHERE ((NewBusinessLineItem.Sold='Yes')) AND (([NewBusinessHeader].[Process_Complete_Date])>=<<Enter the From Date[Date]>> AND [NewBusinessHeader].[Process_Complete_Date]<= <<Enter the To Date[Date]>>) AND (((NewBusinessHeader.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))

UNION ALL

SELECT Submissions.Exec_Name, Submissions.Client_Last_Name,Submissions.EffectiveDate,Submissions.Carrier, Submissions.LineOfBusiness,Submissions.SoldPremium,Submissions.Sold,Submissions.Referral_Source,Submissions.Branch,Submissions.Dept,Submissions.Agency_Rev,Submissions.Process_Complete_Date,Submissions.Group_Submission_Number

FROM Submissions

WHERE ((Submissions.Sold='Yes')) AND Process_Complete_Date >= <<Enter the From Date[Date]>> AND Process_Complete_Date<= <<Enter the To Date[Date]>> AND (((Submissions.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))

Open in new window

0
Comment
Question by:Newbi22
3 Comments
 
LVL 19

Accepted Solution

by:
Bhavesh Shah earned 300 total points
ID: 39600405
try with this

SELECT * FROM
(
SELECT NewBusinessHeader.Exec_Name, NewBusinessHeader.Client_Last_Name, NewBusinessLineItem.EffectiveDate, NewBusinessLineItem.Carrier, NewBusinessLineItem.LineOfBusiness, NewBusinessLineItem.SoldPremium, NewBusinessLineItem.Sold, NewBusinessHeader.Referral_Source,NewBusinessHeader.Branch,NewBusinessHeader.Dept,NewBusinessHeader.Customer_Number as Agency_Rev,NewBusinessHeader.Process_Complete_Date,NewBusinessHeader.Group_Submission_Number

FROM NewBusinessHeader INNER JOIN NewBusinessLineItem ON NewBusinessHeader.NBHeaderID = NewBusinessLineItem.NBHeaderID

WHERE ((NewBusinessLineItem.Sold='Yes')) AND (([NewBusinessHeader].[Process_Complete_Date])>=<<Enter the From Date[Date]>> AND [NewBusinessHeader].[Process_Complete_Date]<= <<Enter the To Date[Date]>>) AND (((NewBusinessHeader.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))

UNION ALL

SELECT Submissions.Exec_Name, Submissions.Client_Last_Name,Submissions.EffectiveDate,Submissions.Carrier, Submissions.LineOfBusiness,Submissions.SoldPremium,Submissions.Sold,Submissions.Referral_Source,Submissions.Branch,Submissions.Dept,Submissions.Agency_Rev,Submissions.Process_Complete_Date,Submissions.Group_Submission_Number

FROM Submissions

WHERE ((Submissions.Sold='Yes')) AND Process_Complete_Date >= <<Enter the From Date[Date]>> AND Process_Complete_Date<= <<Enter the To Date[Date]>> AND (((Submissions.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))
)AS A
WHERE Referral_Source IS NOT NULL OR Referral_Source = ''

Open in new window

0
 
LVL 40

Assisted Solution

by:Sharath
Sharath earned 200 total points
ID: 39601039
>> Where Referral_Source is NOT NULL OR BLANK/EMPTY.

For this, "WHERE Referral_Source IS NOT NULL" is sufficient

>> Where Referral_Source is NOT NULL OR NOT BLANK/EMPTY.

For this "WHERE Referral_Source <> ''" is needed.

Modified Brichsoft solution. for this.
SELECT * FROM
(
SELECT NewBusinessHeader.Exec_Name, NewBusinessHeader.Client_Last_Name, NewBusinessLineItem.EffectiveDate, NewBusinessLineItem.Carrier, NewBusinessLineItem.LineOfBusiness, NewBusinessLineItem.SoldPremium, NewBusinessLineItem.Sold, NewBusinessHeader.Referral_Source,NewBusinessHeader.Branch,NewBusinessHeader.Dept,NewBusinessHeader.Customer_Number as Agency_Rev,NewBusinessHeader.Process_Complete_Date,NewBusinessHeader.Group_Submission_Number

FROM NewBusinessHeader INNER JOIN NewBusinessLineItem ON NewBusinessHeader.NBHeaderID = NewBusinessLineItem.NBHeaderID

WHERE ((NewBusinessLineItem.Sold='Yes')) AND (([NewBusinessHeader].[Process_Complete_Date])>=<<Enter the From Date[Date]>> AND [NewBusinessHeader].[Process_Complete_Date]<= <<Enter the To Date[Date]>>) AND (((NewBusinessHeader.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))

UNION ALL

SELECT Submissions.Exec_Name, Submissions.Client_Last_Name,Submissions.EffectiveDate,Submissions.Carrier, Submissions.LineOfBusiness,Submissions.SoldPremium,Submissions.Sold,Submissions.Referral_Source,Submissions.Branch,Submissions.Dept,Submissions.Agency_Rev,Submissions.Process_Complete_Date,Submissions.Group_Submission_Number

FROM Submissions

WHERE ((Submissions.Sold='Yes')) AND Process_Complete_Date >= <<Enter the From Date[Date]>> AND Process_Complete_Date<= <<Enter the To Date[Date]>> AND (((Submissions.Dept) In (<<Enter Personal Lines, Commercial Lines, Benefit lines (seperated by a comma for mulitple) [Text]+>>)))
)AS A
WHERE Referral_Source <> ''

Open in new window

0
 

Author Closing Comment

by:Newbi22
ID: 39634465
thnka for the assistance. I got it now.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question