Solved

Indicator based on the Categories

Posted on 2014-09-09
9
64 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
ID: 40312130
select * from yourtable where category like '%Non%'

Open in new window

Not 100% on what your looking for
0
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40312140
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
ID: 40312182
I'm looking for a SQL from that table with a case statement for the Indicator logic.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 65

Expert Comment

by:Jim Horn
ID: 40312194
The above experts correctly answered your question.  
Why do you need a CASE?
0
 

Author Comment

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

Author Comment

by:pvsbandi
ID: 40312234
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
ID: 40312367
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:Scott Pletcher
Scott Pletcher earned 250 total points
ID: 40312393
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
ID: 40312792
Thank You!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

785 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