Solved

Indicator based on the Categories

Posted on 2014-09-09
9
62 Views
Last Modified: 2014-09-09
Greetings,

 I have data like this:
Category		        Amt	           Indicator
CC_EL			123.00
CC_Non_EL		300.00
RR_EL			200.00
RR_Non_EL		250.00

Open in new window


I need logic for an indicator that will exclude the Non_EL payments (Row 2 and Row 4) or include all the payments. Can someone please help?
0
Comment
Question by:pvsbandi
9 Comments
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
select * from yourtable where category like '%Non%'

Open in new window

Not 100% on what your looking for
0
 
LVL 14

Expert Comment

by:Vikas Garg
Comment Utility
Update Table
set Indicator = case when Category like '%Non%'  then 'Include' else 'Exclude' end

Open in new window

This will set value in indicator to include and exclude

Hope this will help
0
 

Author Comment

by:pvsbandi
Comment Utility
I'm looking for a SQL from that table with a case statement for the Indicator logic.
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
The above experts correctly answered your question.  
Why do you need a CASE?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:pvsbandi
Comment Utility
I'm not updating the table. I need to derive the logic based on SQL statement on that table.
0
 

Author Comment

by:pvsbandi
Comment Utility
Also, if the Indicator is "Y", then the result shall be
Category		        Amt	        
CC_EL			123.00
CC_Non_EL		300.00
RR_EL			200.00
RR_Non_EL		250.00

Open in new window

If the Indicator is "N", then the result shall be
Category		        Amt	        
CC_EL			123.00
RR_EL			200.00

Open in new window

0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 250 total points
Comment Utility
declare @ind varchar(1)
set @ind='Y'
select * from yourtable where (category like '%Non%' and @ind='N') or (@Ind='Y')

Open in new window

or if you want to build your string
select * from yourtable where (category like '%Non%' and Indicator='N') or (Indicator='Y')

Open in new window

0
 
LVL 69

Assisted Solution

by:ScottPletcher
ScottPletcher earned 250 total points
Comment Utility
DECLARE @include_non_EL bit
SET @include_non_EL = 1

SELECT Category, Amt, Indicator
FROM tablename
WHERE
    (@include_non_EL = 1 OR Category NOT LIKE '%Non_EL%')
0
 

Author Closing Comment

by:pvsbandi
Comment Utility
Thank You!
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now