Query of Query Case Sensative
Hello all
Got a simple problem, I run a main query:
<CFQUERY name="getprice" datasource="adatabase">
SELECT RTRIM(plpart) AS plpart, MIN(plunitprice) AS
plunitprice
FROM pricelist
GROUP BY plpart
</CFQUERY>
now in the table pricelist some parts are entered in
lowercase i.e the results could look like below:
Part____Price
ABc, 10
DeF, 11
ghi, 12
JKL, 10
If I query the datasource direct there is no problem with the
case being upper or lower, but when I query of query like below it
only returns a result if the LIKE '#variable#' is the correct case,
how do I get around this?
<CFquery dbtype="query" name="qoq_price">
SELECT plunitprice
From getprice
WHERE plpart LIKE '#variable#'
</CFquery>
for example
if variable was 'ABc' the QOQ returns the correct price of 10
but
if variable was 'ABC' the QOQ does not return a result
Trouble is my variables come from one table where they are
all in Upper case but in my price table people have entered them in
both cases and sometimes mixed.
Kind Regards Guy
The bold bit throws an error
Query Of Queries syntax error.
Encountered "( plpart ) LIKE" at line 4, column 12. Incorrect
conditional expression, Expected one of
[like|null|between|in|comparison] condition, Unrecognized
comparison operator,
WHERE
UCase(plpart) LIKE '#UCase(Variable)#'
This works
WHERE plpart LIKE '#UCase(Variable)#'
But then im turning the wrong side into upper case.
I need a kind of no case or ignore case format so in PSUDO it
would be somthing like
WHERE plpart LIKE #ignorecase(#variable#)#
if you see what i mean.
Regards Guy
Similar Messages
-
Case Sensative Search - Content ID
Hey
I'm working in a new environment and have noticed that when I do a search through the web client using Content Id the search is case-sensative.
For example:
Search for: RACCONT024190
Returns: 1 item
Search for: raccont024190
Returns: 0 item
I don't remember this being an issue at my last site. Any ideas what is causing it, or is this working as it is supposed to?
Current env: 11gR1-11.1.1.6.0-idcprod1-120501T084637 (Build:7.3.3.183)
Regards,
AlecHi ,
Do you have OracleCaseInsensitive component enabled on the older instance ? If yes , then that is the reason why it is working fine there .
To achieve case insensitive search results install the above component from UCM 10g patchset .
Thanks
Srinath -
SQL Query CASE statement using two fields
Hi,
I have two fields. One is called rescategory1, the other is called rescategory2.
I'm not sure if its a CASE statement I need or some sort of WHERE clause but I want to create a query that does the following or something similar:
CASE rescategory2
WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
END AS [Resolution Sub Category]
Basically, I'm looking to give rescategory2 a value based on that of rescategory1 and rescategory2 combined.
How do I write this?
Cheers
Pauldo you mean this?
rescategory2 = CASE
WHEN rescategory1 = '44' AND rescategory2 = '1' THEN 'Backup'
WHEN rescategory1 = '44' AND rescategory2 = '2' THEN 'Hardware'
END
ie assigning value for rescategory2
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Grouping using report query / Case statement in toplink
I have following tables
1. Student with columns id, gender
2. Subject_Score with columns id, student_id, subject_id, score
To get scores grouped by subject, I am doing
ExpressionBuilder subjScoreBuilder = new ExpressionBuilder();
ReportQuery query = new ReportQuery(SubjectScore.class);
query.addAverage("average-score",subjScoreBuilder.get("score"));
query.addGrouping(subjScoreBuilder.get("subjectId"));
Vector responses = (Vector) serverSession.executeQuery(query);
Float score = (Float) queryResult.get("average-score");
This works fine. It gives avg score per each subject
Now i want both in one query
A) avg score per subject
B) avg score per subject per gender
I want to achive this in one query
I am doing like:
ExpressionBuilder subjScoreBuilder =new ExpressionBuilder(SubjectScore.class);
ExpressionBuilder studentExpBuilder = new ExpressionBuilder(Student.class);
Expression expression = subjScoreBuilder.get("studentid").equal(studentExpBuilder.get("id")));
ReportQuery query = new ReportQuery(SubjectScore.class, expression);
query.addAverage("average-score", subjScoreBuilder.get("score"));
query.addGrouping( subjScoreBuilder.get("subjectId"));
query.addGrouping( studentExpBuilder.get("gender"));
This gives me avg scor per each subject per gender. i.e.
it applies grouping on both subjectId & gender.
This is fine.
But I also want avg score per each subject (group on subject only) in same query.
1. How can we achive it?
2. is there something like Case statement in toplink?
Thanks a lot for any help.I believe in SQL you would need two queries to do this directly, so you will need to issue two queries.
You could select the Count and Avg, this would give you all the data need to compute the Avg yourself.
i.e.
(count(male) * avg(male) + count(female) * avg(female)) / (count(male) + count(female)) -
HI Friends ,
My Scenario in table data :
EmpId fromdate todate Billtype
2 01-09-2014 09-09-2014 B
3 01-09-2014 NULL B
2 10-09-2014 NULL P
4 01-09-2014 NULL U
5 01-09-2014 15-09-2014 B
5 16-09-2014 30-09-2014 U
OutPut :
EmpId Status
2 P
3 B
4 U
5 P
requirement : Need to develop this Sql Query ..Using the Case statement .
Please Help
thanks
RakeshWonderfull Patrick......
I executed the logic and returning the expected result . Thanks a lot.
But still need some more modification ......
suppose an employee E7 has the following entry :
E7 01-04-2014 20-06-2014 B
E7 21-06-2014 Null P
This means that the Employee E7 has Joined Project P1 in April First on a Billed Project and worked till July 20th and then again Moved to a Partial Billing Project P3 and from that July Till working in that Project
So as per logic , we are suppose to get the Status of the Employees in the previous Month.....logically means October...... so for the same E7 the Status would be "P"...because from July he is working on a Partial Billed Project
..... If suppose E7 worked on an Unbilled Project from July .... then for the month of October ......the Status for the same E7 would be "U"
Soooo ......if Employee E8 made 2 transitions within a month take example of last month October .
E7 01-04-2014 20-06-2014 B
E7 21-06-2014 Null P
E8 01-10-2014 20-10-2014 B
E8 21-10-2014 23-10-2014 P
E8 24-10-2014 Null/Empty U
so for this employee the Result for the November month will be "P" but if i check in month of december ...... for the same the satus should be "U" because from the last October 24th he is working on a "UnBilled Project"
Please Help ......!!!
I think what you need is just a filter like below
declare @FromDate datetime
SET @FromDate ='20141001'
SELECT EmpId,
CASE WHEN MAX(Billtype) = 'B' THEN 'B'
WHEN MIN(Billtype) = 'U' THEN 'U'
ELSE 'P'
END AS Status
FROM table
WHERE fromdate >= @FromDate
OR (fromdate < @Fromdate
AND (todate > @FromDate
OR todate IS NULL))
GROUP BY EmpId
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Excel Query case sensitive problem
HI all I am writing query in excel to join table. however I find it is case sensitive. which cause many trouble.
how to make it case incensitive.
SELECT *
FROM `C:\compare.xlsx`.`sheet1$` a
left join `C:\compare.xlsx`.`sheet2$` b
on a.`name`=b.`name`
union
SELECT *
FROM `C:\compare.xlsx`.`sheet1
right join `C:\compare.xlsx`.`sheet2$` d
on c.`name`=d.`name`Hi,
I tested it with my data source (I create it like this, not use all of the month). Would you like to share us a sample file through OneDrive if possible?
If you have further question about the SQL sentence, I recommend you post your issue to SQL forum.
http://social.technet.microsoft.com/Forums/en-US/home?category=sqlserver
Regards,
George Zhao
TechNet Community Support -
TSQL - Dynamic Query Case statment update issue - to update table by left shifting the rows
Hi all
I need an help on my tsql query in 2000 to fix the case statement.
I have a table like shown below.
On this table where ever I see PortID as 101 and 105 I need to remove it and shift the rows from right to left.
ie on First row PortID1 is 101 so I need to remove it and replace it with PortId2 and similarly PortID2 replaced my PortID3 and so on.
ie like on excel if you delete cell we need to shift the rows to left .
I wrote an dynamic update statement i,m not sure on the assigning dynamic case statment.
CREATE TABLE [TravelRank]
[Destination] [varchar] (50) NULL,
[PortID1] [int] NULL ,
[Distance1] [int] NULL ,
[Rating1] [int] NULL ,
[PortID2] [int] NULL ,
[Distance2] [int] NULL ,
[Rating2] [int] NULL ,
[PortID3] [int] NULL ,
[Distance3] [int] NULL ,
[Rating3] [int] NULL ,
[PortID4] [int] NULL ,
[Distance4] [int] NULL ,
[Rating4] [int] NULL
INSERT into [TravelRank]
select 'Virgin Islands','101','10','5','102','20','5','103','31','5','109','41','5'
Union all
select 'Guinea','101','15','3','102','22','3','105','32','2','110','45','4'
Union all
select 'Benin ','102','12','4','106','28','4','104','33','3','109','48','2'
Union all
select 'Ecuador','102','18','5','101','29','5','108','34','1','111','45','5'
Union all
select 'Belarus ','103','17','4','105','24','4','108','45','4','112','46','3'
Union all
select 'Cook Islands','105','11','2','108','23','2','101','32','2','107','42','4'
Here is my code to fix
declare @SQL varchar(4000)
declare @left varchar(1)
declare @right varchar(1)
select @left = '1',@right = '2'
while @left < 4
begin
select @SQL = '
update t1.PortID' + @left + ' = t2.PortID' + @right + '
t1.Distance' + @left + ' = t2.Distance' + @right + '
t1.Rating' + @left + ' = t2.Rating' + @right + '
'case @left
when '1' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
' when '2' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
' when '3' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
' when '3' then
' t1.PortID' + @left + ' = null '
t1.Distance' + @left + ' = null '
t1.Rating' + @left + ' = null '
else '' end'
from [TravelRank] t1
inner join [TravelRank] t2
on t1.destination = t2.destination
where t1.PortID1 = 101'
print @SQL
-- exec (@SQL)
select @left = cast(cast(@left as int) + 1 as varchar(1))
, @right = cast(cast(@right as int) + 1 as varchar(1))
end
Thanks a lot in advance.declare @SQL varchar(4000)
declare @left varchar(1)
declare @right varchar(1)
select @left = '1',@right = '2'
while @left < 4
begin
select @SQL = '
update t1.PortID' + @left + ' = t2.PortID' + @right + '
t1.Distance' + @left + ' = t2.Distance' + @right + '
t1.Rating' + @left + ' = t2.Rating' + @right + '
'+CASE @left
when '1' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+3 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+3 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+3 as varchar(1)) +'
' when '2' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.PortID' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+2 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+2 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+2 as varchar(1)) +'
' when '3' then
' t1.PortID' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.PortID' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Distance' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Distance' + cast(cast(@right as int)+1 as varchar(1)) +'
t1.Rating' + cast(cast(@left as int)+1 as varchar(1)) + ' = t2.Rating' + cast(cast(@right as int)+1 as varchar(1)) +'
' when '3' then
' t1.PortID' + @left + ' = null '+
' t1.Distance' + @left + ' = null '+
' t1.Rating' + @left + ' = null '
else '' END + '
from [TravelRank] t1
inner join [TravelRank] t2
on t1.destination = t2.destination
where t1.PortID1 = 101'
print @SQL
-- exec (@SQL)
select @left = cast(cast(@left as int) + 1 as varchar(1))
, @right = cast(cast(@right as int) + 1 as varchar(1))
end
You were missing a couple of concats. This runs now, but I'm not completely sure if it's the output you were expecting. -
Select query case insensitive for data type VARG
Hi Experts,
I am having trouble in retrieving the results from a table using select query.
I have a table (Users) as below
Name (VARG) Number(INTEGER)
Murthy 0001
murthy 0002
when I am querying the table with select query as -
select * from Users where Name = 'Murthy'
this query is returning only one record which matches with capital letter of 'M', though both the record names are same.
I have seen in IBM forum to make the select query as case insensitive using the UPPER key word, I have tried this as below -
select * from Users where UPPER(Name) = 'MURTHY'
But this query is not working in my case...
My DB2 version is 8.1.5
Can any one please help in fixing this problem...
Thanks in Advance,
MurthyHi Murthy,
your query is the right to one to select both records. I don't see why it doesn't work.
Are you sure you posted the query that you have executed ?
What is the result of this query ?
But i don't really know how an VARG (Varying-length graphic string) will work. It could be that the UPPER-Function will work in another way as it works on VARCHAR.
regards
Kay -
Select query, case statment
Hi,
I have two tables Registration and Place.
"Registration" table has Name and Registration_id column and "place" table has Registration_id, task_id and state columns. So both tables have inner join on Registration_id column.
now one Registration_id has two task_id
so for example,
Name
Registration_id
task_id
State
Vicky
101
11
NY
Vicky
101
12
CA
Now in output table "Person", I have 2 columns, one is Birth and one is Death.
So one person has 1 Registration_id associated and that Registration_id has two records in "Place" table,
Now condition is like this, for same Registration_id if task_id = 11 put state value in Birth column and if task_id = 12 put state value in Death column.
So for example output (Select query for Person table)should looks like below,
Name
Registration_id
Birth
Death
Vicky
101
NY
CA
So please tell me select query for this output from above 2 source tables which I use to insert records into "Person" table. (Just for information - I have 12 source tables and there are many columns I have to select from these source tables
and this is the part of that select statement where I am stuck for now). Please let me know if you need any more detail on this.
I think, we have to write subquery in select statement. like,
Select
Birth =(select
STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
where
TASK_ID = 136)
, Death
=(select
STATE from PLACE pl inner join on Registration R ON R.Registration_id = pl.Registration_id
where
TASK_ID = 141)
, other columns
From other source tables.
Thank you in advance.
Vicky>> I have two tables Registration and Place [only one?]. <<
Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on sql forums. You have been told about this before!! Why do you still behave like this? PLEASE EXPLAIN TO EVERYONE HERE WHY THE MOST BASIC SOCIAL RULES DO NOT APPLY TO YOU??
>> Please let me know if you need any more detail on this. <<
WE NEED EVERYTHING! You posted nothing. You do not even know that you should have had “state_code CHAR(2) NOT NULL” in some DDL. You still not know that rows are not records, that tables models sets not single items, etc.
Please quit posting until you come up to the level of a total noob who read the forum rules.
We get tired of doing homework for people who are ignorant, incompetent and rude.
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
I've begun to notice that not all apps support case-sensitive partitions. I know that repartitioning or reformatting will just wipe everything and conversions don't usually work because of naming overlaps. But I had an idea. What if I created a second, case-insensitive partition? You see I have 100GB free. So if I create a 100GB partition, move 100GBs over, resize the partition into the new free space and repeat. Soon I would have all my files moved onto a new case-insensitive partition, and I could delete the old one and completely take it's place.
The only problem I see is the OS. I know the files won't mind the move, but the OS I'm sure is a problem. Maybe I could make the 2nd partition, install mac on it, and then move my other files over bit by bit, resizing the partition as I go. Is there a way to import my prefs and settings from an adjoining partition?
I just want to know what the problems with my idea might be. Is it risky? Am I a mad man?Yes. Just select the volume in Disk Utility and select erase. Case-sensitivy is selectable. However, I've never understood the PC case-sensitivity usage and would never recommend it. Finally, AFAIK, the OS handles either.
-
Creating a case-sensative partition
Hello,
I need to create a case-sensitive partition on my laptop so that I can check out source code using Subversion. One of my co-workers said that I should be able to use the Disk Utility to create a partition with Mac OS Extended (Journalled, Case-sensitive) format. I see how to add additional partitions using Disk Utility, but I am only able to select Mac OS Extended (Journalled) format in the Format: drop-down menu. A case-sensitive option does not appear.
Am I only able to format subsequent partitions with the same format as the original partition? Also, will creating this additional partition erase the data contained in the original partition that will be shrunk?
Thanks,
Adrianadrian.down wrote:
Hello,
I need to create a case-sensitive partition on my laptop so that I can check out source code using Subversion. One of my co-workers said that I should be able to use the Disk Utility to create a partition with Mac OS Extended (Journalled, Case-sensitive) format. I see how to add additional partitions using Disk Utility, but I am only able to select Mac OS Extended (Journalled) format in the Format: drop-down menu. A case-sensitive option does not appear.
you can reformat those new partitions later cases sensitive using the "erase" tab.
Am I only able to format subsequent partitions with the same format as the original partition? Also, will creating this additional partition erase the data contained in the original partition that will be shrunk?
no, it won't erase that data. do make sure that you have plenty of free space when creating the new partition. Otherwise the partitioning process may fail.
Thanks,
Adrian -
Account Lookup Case sensative - make insensative
Hello,
When looking up an account or searching for an account within the application is there a way to make the Account Lookup field not be case sensitive or a wild card that can be added. The "is like" doesn't work.
ThanksCor, at this time the account lookup is case sensitive. However, the search capability in the action bar on the left is not case sensitive.
-
How can I tell if my disc is case-sensative?
I got to Disk Utility and select the drive, then click on "info". I don't see anything about case sensitivity listed. I see:
File System: Mac OS Extended (Journaled)
Partition type: Apple_HFS
and other non-related items.Alfredo Jahn wrote:
I got to Disk Utility and select the drive, then click on "info". I don't see anything about case sensitivity listed. I see:
File System: Mac OS Extended (Journaled)
That tells you it's not. If it were case-sensitive, it would say either +Mac OS Extended (Case-Sensitive)+ or +Mac OS Extended (Case-sensitive, Journalled).+
See the pink box in #5 of Time Machine - Frequently Asked Questions (or use the link in *User Tips* at the top of this forum), for more information. -
Hi, I have two issues, here is my initial code:
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.
To get around this I did the following which is not very efficient and I'm hoping it can be improved:
select distinct z.cla_case_no from (
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_MW_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
SELECT
ie ,(select distinct z.cla_case_no from (
select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5
FROM etc
Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
Thanks!!!
Banner:
Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
PL/SQL Release 11.2.0.2.0 - Production
"CORE 11.2.0.2.0 Production"
TNS for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - ProductionHi,
It looks like you have another copy of this question:
Case Statement and sub query
That's probably not your fault, but you should mark the other copy as "Answered" right away, and then you'll only have to look for replies in one place.
885178 wrote:
... Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.If you know there will only be one, then you can use LAST, and you don't need GrOUP BY
To get around this I did the following which is not very efficient and I'm hoping it can be improved:
select distinct z.cla_case_no from (
select
cc.name_id_no
,cc.discover_date
,cc.cla_case_no
,max(rl.year_of_incident)Non_MW_Loss_Past_5
,rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) zHere's one way:
SELECT MIN (cla_case_no) KEEP (DENSE_RANK LAST ORDER BY r1.year_of_incident)
AS latest_cla_case_no
FROM cla_case cc
, rbn_loss rl
WHERE cc.name_id_no = rl.customer_no
AND rl.year_of_incident > TRUNC (cc.discover_date) - 1095
AND rl.year_of_incident < TRUNC (cc.discover_date)
AND rl.type_of_loss < 1000
AND rl.timestamp < TRUNC (cc.discover_date)
AND cc.question_class IN (20, 25)
;If you'd post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data, then I could test this.
Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
SELECT
ie ,(select distinct z.cla_case_no from (
select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
from cla_case cc, rbn_loss rl
where cc.name_id_no = rl.customer_no
and rl.year_of_incident < trunc(cc.discover_date)
and rl.type_of_loss < 1000
and rl.timestamp < trunc(cc.discover_date)
and (cc.question_class = 20
or cc.question_class = 25)
and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
--and (trunc(cc.discover_date) <> (rl.year_of_incident))
group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
) z
where z.cla_case_no = ccx.cla_case_no
) Non_MW_Loss_Past_5
FROM etc
Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
NVL2 (x, 'Y', 'N')returns 'Y' if x is NULL, and it returns 'N' if x is not NULL. X can be a scalar sub-query:
NVL2 ((SELECT ...), 'Y', 'N')You could also use an EXISTS sub-query:
CASE
WHEN EXISTS (SELECT ...)
THEN 'Y'
ELSE 'N'
END -
Help to rewrite the query --performance issue
Hi ,
Please help to rewrite the query since it's performance is not good.Especially second inline query(CASE statements are therein select caluse ..)is taking more cost.
Database Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
SELECT *
FROM
(SELECT q.*,
COUNT(*) OVER() AS record_count,
ROWNUM AS row_num
FROM
(SELECT ExName.examiner_code,
examiner_name,
:v_year,
:v_month,
count_fb,
NVL(count_entered_fb, 0) count_entered_fb,
NVL(count_sent_fb, 0) count_sent_fb,
NVL(count_edited_fb, 0) count_edited_fb,
NVL(count_complete_fb, 0) count_complete_fb,
NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb
FROM
(SELECT examiner_code,
COUNT(*) AS count_fb
FROM
(SELECT
examiner_code,
paper_code,
assessment_school
FROM
( SELECT DISTINCT ce.examiner_code,
ce.paper_code,
ce.assessment_school
FROM
(SELECT
DISTINCT assessment_school,
paper_code,
examiner_code
FROM candidate_examiner_allocation cea
WHERE cea.element = 'Moderation of IA'
AND cea.year = :v_year
AND cea.month = :v_month
) ce,
subject_group sg,
subject_component sc
WHERE (:v_padded_examiner_code IS NULL
OR ce.examiner_code = :v_padded_examiner_code)
AND (:v_subject_group IS NULL
OR sg.group_number = :v_subject_group)
AND sg.year = :v_year
AND sg.month = :v_month
AND sc.year = :v_year
AND sc.month = :v_month
AND sc.paper_code = ce.paper_code
AND sc.subject = sg.subject
AND sc.lvl = sg.lvl
AND (:v_subject IS NULL
OR sc.subject = :v_subject)
AND (:v_lvl IS NULL
OR sc.lvl = :v_lvl)
) ea
GROUP BY examiner_code
) ExName,
(SELECT examiner_code,
COUNT(
CASE
WHEN UPPER(wfi.status) = 'ENTERED'
THEN 1
ELSE NULL
END) AS count_entered_fb,
COUNT(
CASE
WHEN UPPER(wfi.status) = 'SENT'
THEN 1
ELSE NULL
END) AS count_sent_fb,
COUNT(
CASE
WHEN UPPER(wfi.status) = 'EDITED'
THEN 1
ELSE NULL
END) AS count_edited_fb,
COUNT(
CASE
WHEN UPPER(wfi.status) = 'COMPLETE'
THEN 1
ELSE NULL
END) AS count_complete_fb,
COUNT(
CASE
WHEN UPPER(wfi.status) = 'WITH IBCARDIFF'
THEN 1
ELSE NULL
END) AS count_withibcardiff_fb
FROM ia_instances ia1,
workflow_instance wfi
WHERE wfi.instance_id = ia1.workflow_instance_id
AND ia1.year = :v_year
AND ia1.month = :v_month
GROUP BY ia1.year,
ia1.month,
examiner_code
) iaF,
(SELECT person_code,
title
|| ' '
|| firstname
|| ' '
|| lastname AS examiner_name
FROM person
WHERE :v_examiner_name IS NULL
OR UPPER(title
|| ' '
|| firstname
|| ' '
|| lastname) LIKE :v_search_examiner_name
) P
WHERE ExName.examiner_code = iaF.examiner_code (+)
AND ExName.examiner_code = p.person_code
ORDER BY ExName.examiner_code
) q
) rc
WHERE row_num >= :v_start_row
AND row_num <= (:v_start_row+(:v_max_row-1));explain plan
line 1: SQLPLUS Command Skipped: set linesize 130
line 2: SQLPLUS Command Skipped: set pagesize 0
PLAN_TABLE_OUTPUT
Plan hash value: 1581970599
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 276 | | 2187 (6)| 00:00:34 |
|* 1 | FILTER | | | | | | |
|* 2 | VIEW | | 1 | 276 | | 2187 (6)| 00:00:34 |
| 3 | WINDOW BUFFER | | 1 | 250 | | 2187 (6)| 00:00:34 |
| 4 | COUNT | | | | | | |
| 5 | VIEW | | 1 | 250 | | 2187 (6)| 00:00:34 |
| 6 | SORT ORDER BY | | 1 | 119 | | 2187 (6)| 00:00:34 |
| 7 | NESTED LOOPS | | 1 | 119 | | 2186 (6)| 00:00:34 |
|* 8 | HASH JOIN OUTER | | 1 | 92 | | 2185 (6)| 00:00:34 |
| 9 | VIEW | | 1 | 20 | | 51 (4)| 00:00:01 |
| 10 | SORT GROUP BY | | 1 | 7 | | 51 (4)| 00:00:01 |
| 11 | VIEW | | 1 | 7 | | 51 (4)| 00:00:01 |
| 12 | SORT UNIQUE | | 1 | 127 | | 51 (4)| 00:00:01 |
| 13 | NESTED LOOPS | | 1 | 127 | | 50 (2)| 00:00:01 |
|* 14 | HASH JOIN | | 1 | 68 | | 44 (3)| 00:00:01 |
|* 15 | TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT | 13 | 520 | | 40 (0)| 00:00:01 |
|* 16 | INDEX RANGE SCAN | SUBJECT_COMPONENT_ASSESS_TYPE | 1059 | | | 9 (0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | SUBJECT_GROUP_PK | 41 | 1148 | | 3 (0)| 00:00:01 |
|* 18 | INDEX RANGE SCAN | CEA_AUTOMATIC_ALLOCATION_STATS | 5 | 295 | | 6 (0)| 00:00:01 |
| 19 | VIEW | | 679 | 48888 | | 2133 (6)| 00:00:33 |
| 20 | SORT GROUP BY | | 679 | 25123 | | 2133 (6)| 00:00:33 |
|* 21 | HASH JOIN | | 52408 | 1893K| 1744K| 2126 (6)| 00:00:33 |
| 22 | TABLE ACCESS BY INDEX ROWID | IA_INSTANCES | 52408 | 1125K| | 688 (1)| 00:00:11 |
|* 23 | INDEX RANGE SCAN | IND_IA_INSTANCES | 49077 | | | 137 (2)| 00:00:03 |
| 24 | TABLE ACCESS FULL | WORKFLOW_INSTANCE | 1075K| 15M| | 960 (7)| 00:00:15 |
|* 25 | TABLE ACCESS BY INDEX ROWID | PERSON | 1 | 27 | | 1 (0)| 00:00:01 |
|* 26 | INDEX UNIQUE SCAN | PERSON_PK | 1 | | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))
2 - filter("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))
8 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE"(+))
14 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")
15 - filter((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL))
16 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)
17 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)
filter(:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP))
18 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND
"CEA"."ELEMENT"='Moderation of IA')
filter("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR
"EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE))
21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")
23 - access("IA1"."YEAR"=TO_NUMBER(:V_YEAR) AND "IA1"."MONTH"=:V_MONTH)
25 - filter(:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME)
26 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")
53 rows selectedHi,
please find the below rigjt explan paln.
PLAN_TABLE_OUTPUT
SQL_ID 2ct41vyyzqyh7, child number 0
SELECT * FROM (SELECT q.*, COUNT(*) OVER() AS record_count, ROWNUM AS row_num FROM (SELECT
ExName.examiner_code, examiner_name, :v_year, :v_month, count_fb, NVL(count_entered_fb,
0) count_entered_fb, NVL(count_sent_fb, 0) count_sent_fb, NVL(count_edited_fb, 0) count_edited_fb,
NVL(count_complete_fb, 0) count_complete_fb, NVL(count_withibcardiff_fb, 0) count_withibcardiff_fb FROM
(SELECT examiner_code, COUNT(*) AS count_fb FROM (SELECT
examiner_code, paper_code, assessment_school FROM ( SELECT DISTINCT
ce.examiner_code, ce.paper_code, ce.assessment_school FROM (SELECT
DISTINCT assessment_school,
paper_code, examiner
Plan hash value: 651311258
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | | 2785 (100)| |
|* 1 | FILTER | | | | | | |
|* 2 | VIEW | | 4 | 1104 | | 2785 (7)| 00:00:43 |
| 3 | WINDOW BUFFER | | 4 | 1000 | | 2785 (7)| 00:00:43 |
| 4 | COUNT | | | | | | |
| 5 | VIEW | | 4 | 1000 | | 2785 (7)| 00:00:43 |
| 6 | NESTED LOOPS | | 4 | 476 | | 2785 (7)| 00:00:43 |
| 7 | MERGE JOIN OUTER | | 4 | 368 | | 2781 (7)| 00:00:43 |
| 8 | VIEW | | 4 | 80 | | 72 (3)| 00:00:02 |
| 9 | SORT GROUP BY | | 4 | 28 | | 72 (3)| 00:00:02 |
| 10 | VIEW | | 4 | 28 | | 72 (3)| 00:00:02 |
| 11 | SORT UNIQUE | | 4 | 508 | | 72 (3)| 00:00:02 |
| 12 | NESTED LOOPS | | 4 | 508 | | 71 (2)| 00:00:02 |
|* 13 | HASH JOIN | | 1 | 68 | | 44 (3)| 00:00:01 |
|* 14 | TABLE ACCESS BY INDEX ROWID| SUBJECT_COMPONENT | 13 | 520 | | 40 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | SUBJECT_COMPONENT_ASSESS_TYPE | 1059 | | | 9 (0)| 00:00:01 |
|* 16 | INDEX RANGE SCAN | SUBJECT_GROUP_PK | 41 | 1148 | | 3 (0)| 00:00:01 |
|* 17 | INDEX RANGE SCAN | CEA_AUTOMATIC_ALLOCATION_STATS | 30 | 1770 | | 27 (0)| 00:00:01 |
|* 18 | SORT JOIN | | 576 | 41472 | | 2709 (7)| 00:00:42 |
| 19 | VIEW | | 576 | 41472 | | 2708 (7)| 00:00:42 |
| 20 | SORT GROUP BY | | 576 | 21312 | | 2708 (7)| 00:00:42 |
|* 21 | HASH JOIN | | 52408 | 1893K| 1744K| 2701 (7)| 00:00:41 |
|* 22 | TABLE ACCESS FULL | IA_INSTANCES | 52408 | 1125K| | 1263 (6)| 00:00:20 |
| 23 | TABLE ACCESS FULL | WORKFLOW_INSTANCE | 1075K| 15M| | 960 (7)| 00:00:15 |
|* 24 | TABLE ACCESS BY INDEX ROWID | PERSON | 1 | 27 | | 1 (0)| 00:00:01 |
|* 25 | INDEX UNIQUE SCAN | PERSON_PK | 1 | | | 0 (0)| |
Predicate Information (identified by operation id):
1 - filter(TO_NUMBER(:V_START_ROW)<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1))
2 - filter(("ROW_NUM">=TO_NUMBER(:V_START_ROW) AND "ROW_NUM"<=TO_NUMBER(:V_START_ROW)+(TO_NUMBER(:V_MAX_ROW)-1)))
13 - access("SC"."SUBJECT"="SG"."SUBJECT" AND "SC"."LVL"="SG"."LVL")
14 - filter(((:V_SUBJECT IS NULL OR "SC"."SUBJECT"=:V_SUBJECT) AND ("SC"."LVL"=:V_LVL OR :V_LVL IS NULL)))
15 - access("SC"."YEAR"=TO_NUMBER(:V_YEAR) AND "SC"."MONTH"=:V_MONTH)
16 - access("SG"."YEAR"=TO_NUMBER(:V_YEAR) AND "SG"."MONTH"=:V_MONTH)
filter((:V_SUBJECT_GROUP IS NULL OR "SG"."GROUP_NUMBER"=TO_NUMBER(:V_SUBJECT_GROUP)))
17 - access("CEA"."YEAR"=TO_NUMBER(:V_YEAR) AND "CEA"."MONTH"=:V_MONTH AND "SC"."PAPER_CODE"="PAPER_CODE" AND
"CEA"."ELEMENT"='Moderation of IA')
filter(("CEA"."ELEMENT"='Moderation of IA' AND (:V_PADDED_EXAMINER_CODE IS NULL OR
"EXAMINER_CODE"=:V_PADDED_EXAMINER_CODE)))
18 - access("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")
filter("EXNAME"."EXAMINER_CODE"="IAF"."EXAMINER_CODE")
21 - access("WFI"."INSTANCE_ID"="IA1"."WORKFLOW_INSTANCE_ID")
22 - filter(("IA1"."MONTH"=:V_MONTH AND "IA1"."YEAR"=TO_NUMBER(:V_YEAR)))
24 - filter((:V_EXAMINER_NAME IS NULL OR UPPER("TITLE"||' '||"FIRSTNAME"||' '||"LASTNAME") LIKE :V_SEARCH_EXAMINER_NAME))
25 - access("EXNAME"."EXAMINER_CODE"="PERSON_CODE")
66 rows selected
Maybe you are looking for
-
Not able to see the values properly
Hi,, I am using Jdev 11.1.1.5. I see the value of "val.toString()" is correct and the Sql of the view is fine. Then what can be the reasons that no values come out in the popup? Why do I get "No data to display" within the popup once I clicked the li
-
Hi, We are interfacing data from txt file to the ECC Unicode system. In text file charecters are looks like KÏÂÕ 0,8ÌÌ ÏÐÎÇÐÀ×ÍÛÉ and same charectrers we are able to see in the document which posted by the interface. However, when we upload same file
-
Use Mac while HDMI is using full screen
Hello, I am trying to use the HDMI port to show something full screen on the tv using quickplayer, but would also like to use the Mac screen to use pages, is this possible? many thanks,
-
Daily notes in the calander - where'd they go?
Each day of my recent 35 day vacation I made notes of the activities of the day in my phone's calander. When I go back now, there is nothing on any of the days. I can't find anything in my outlook, either. How do I find all the notes I made?
-
Help-Flash needs to be reinstalled after every reboot
I need a little bit of help and I'm hoping someone might have the solution to my problem. This has been going on for 2-3 weeks now. Flash installs and works perfectly fine. Then when I restart my computer and try to use a program that requires flash