How to validate date using case statement.
I have date like 022212. I split month,date,year using STUFF Function. Now, i have to validate month in range 01-12 and date in range 01-31. Can some one help me with the query.
Thanks, Shyam Reddy.
That is not date; it is apparently a string (we have no DDL because you are so rude). Any competent SQL programmer will use DATE. You want help with a query, but there is no query.
CAST ('20' + SUBSTRING (crap_string_date, 5,2)+'-' + SUBSTRING (crap_string_date, 1,2) + '-' + SUBSTRING (crap_string_date, 3,2) AS DATE) AS redddy_screwed_up_date
--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
Similar Messages
-
How to manipulate arrays using case statements and boolean conditions?
In the vi that is attached I am trying to compare two values in two different arrays and delete the value that is equal to zero. The values of each array are rounded to the closest integer. Then I attempted to apply the ">0" boolean as the condition for my case statement, but I am getting an error. Any tips on manipulating arrays with case statements?
Attachments:
Patient Movement Monitoring.vi 141 KBThank you!!! that was a huge help. I don't think I need the case structures at all. The next part of the code compares the 4 values in the array.
If columns 0 and 1 are both positive -> output 1
If column 0 is negative and 1 is positive -> output 2
If columns 0 and 1 are both negative -> output 3
If column 0 is positive and 1 is negative -> output 4
(0 is x-axis value, 1 is y-axis value.....outputs are assigning quadrants to the combination)
Only one of the "AND" booleans will return true for each index. Is there a way to initialize another array of outputs 1-4 depending on which AND returns true?
Attachments:
Patient Movement Monitoring.vi 144 KB -
How to Retrive Data using Case or any other method
Hi All
i am new to Oracle, i have three tables. 1 )*Person* contains following data
id, Name, DOB
98, sss, 01/01/2009
99, rrr, 01/01/2009
100, rws, 01/01/2009
2) Reference Table Contains Following Data
Person_ID, Ref_type, Reference
98, AAA, jk98923
98, BBB, io9898
99, AAA, nb6666
100, BBB, g10090
now i need all pesons who got reference AAA only, i dont want to use any where clause. this because i have to incoporate this logic in Business Objects Report.
i need output as follows
Person_ID, Name, Reference
98, sss, jk98923
99, rrr, nb6666
100, rws, NULL
guys i know this is so simple for you, please come back to me on this. many thanks in advance
Edited by: user11078264 on 17-Apr-2009 05:46How about something like this (note the WITH clause was used to generate sample data)?
SQL > WITH person AS
2 (
3 SELECT 98 AS ID, 'sss' AS NAME, TO_DATE('01/01/2009','MM/DD/YYYY') AS DOB FROM DUAL UNION ALL
4 SELECT 99 AS ID, 'rrr' AS NAME, TO_DATE('01/01/2009','MM/DD/YYYY') AS DOB FROM DUAL UNION ALL
5 SELECT 100 AS ID, 'rws' AS NAME, TO_DATE('01/01/2009','MM/DD/YYYY') AS DOB FROM DUAL
6 ),
7 reference AS
8 (
9 SELECT 98 AS PERSON_ID, 'AAA' AS REF_TYPE, 'jk98923' AS REFERENCE FROM DUAL UNION ALL
10 SELECT 98 AS PERSON_ID, 'BBB' AS REF_TYPE, 'io9898' AS REFERENCE FROM DUAL UNION ALL
11 SELECT 99 AS PERSON_ID, 'AAA' AS REF_TYPE, 'nb6666' AS REFERENCE FROM DUAL UNION ALL
12 SELECT 100 AS PERSON_ID, 'BBB' AS REF_TYPE, 'g10090' AS REFERENCE FROM DUAL
13 )
14 SELECT PERSON_ID
15 , NAME
16 , MAX(DECODE(REF_TYPE,'AAA',REFERENCE,NULL)) Reference
17 FROM person
18 JOIN reference ON person.id = reference.person_id
19 GROUP BY PERSON_ID, NAME
20 ORDER BY PERSON_ID
21 /
PERSON_ID NAM REFEREN
98 sss jk98923
99 rrr nb6666
100 rws -
How to use CASE statement in WDA
Hi All,
Can any one Please expain me ' How to use CASE statement in Web dynpro ABAP? '
Please give me an example also.
Thanks in Advance !Hi,
The usage of case statement in webdynpro is same as used in general ABAP.
Data: l_id type string.
l_id = wdevent->get_string( 'ID' ).
case l_id.
when 'BTN1'.
when 'BTN2'.
when 'OTHERS'.
endcase.
Regards,
Radhika. -
Hi
I have two tables
employee
empid empname empaddress valid
Employeedetails
empid empname manager
I would like to validate empname from both the tables using case statement and empid as join and update 'valid' column in employee table to y/n.
Please help me with the syntaxHi,
Depending on your requirements:
UPDATE employee e
SET valid = (
SELECT CASE
WHEN COUNT (*) = 0
THEN 'n'
ELSE 'y'
END
FROM employeedetails
WHERE empname = e.empname
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
If you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Sql proposed to use case statement
Hi All
Can anyone help me here
This code works fine,here inthe inner sub queries(b,c,d,e,f),i am getting the weekly counts of usage data from the table mf_wer_OBI_USAGE_reqq.
As this is hitting same table with the similar set of queries so i was adviced to use case statement by taking the wk_1...5 in variable and making the query better
I am unable to figure out how to proceed.
Appreciate your help here.
Thanks
create table mf_wer_OBI_USAGE_reqq_WK
as select x.user_name id,x.mon MONTH_COUNT,x.wk_1 WEEK1_COUNT,x.wk_2 WEEK2_COUNT,x.wk_3 WEEK3_COUNT,x.wk_4 WEEK4_COUNT,x.wk_5 WEEK5_COUNT,x.subject_area_name,
y.EMP_FIRST_NAME FIRSTNAME,y.EMP_LAST_NAME SURNAME,y.E_MAIL_ADDRESS USER_MAILID,y.ouc OUC
from (select a.user_name,a.mon,a.subject_area_name,b.wk_1,c.wk_2,d.wk_3,e.wk_4,f.wk_5
from (select user_name,sum(count_us_st) mon,subject_area_name from mf_wer_OBI_USAGE_reqq group by user_name,subject_area_name) a,
(select user_name,sum(count_us_st) wk_1,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 1 and 7
group by user_name,subject_area_name) b,
(select user_name,sum(count_us_st) wk_2,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 8 and 14
group by user_name,subject_area_name) c,
(select user_name,sum(count_us_st) wk_3,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 15 and 21
group by user_name,subject_area_name) d,
(select user_name,sum(count_us_st) wk_4,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 22 and 28
group by user_name,subject_area_name) e,
(select user_name,sum(count_us_st) wk_5,subject_area_name from mf_wer_OBI_USAGE_reqq where extract(day from start_dt) between 29 and 31
group by user_name,subject_area_name) f
where a.user_name=b.user_name(+)
and a.subject_area_name=b.subject_area_name(+)
and a.user_name=c.user_name(+)
and a.subject_area_name=c.subject_area_name(+)
and a.user_name=d.user_name(+)
and a.subject_area_name=d.subject_area_name(+)
and a.user_name=e.user_name(+)
and a.subject_area_name=e.subject_area_name(+)
and a.user_name=f.user_name(+)
and a.subject_area_name=f.subject_area_name(+)) x,
dm_employee y
where x.user_name=y.id and
y.active_flg='Y';Swas_fly wrote:
This code works fineIf it's fine, why try to fix it?
Post your table (only the relevant columns as a CREATE TABLE statement) and some sample data (INSERT into) and your required output.
Post your code between these tags: -
Checking for the condition types using case statement
hi folks,
I have a lot of condition types that I have to check for and I am using case statement to do that. The code goes like this.
case wac-kschl.
when 'ZRAT' OR 'ZAGR' OR 'ZRCR' OR
'Y098' OR 'Y007' OR 'ZREW' OR 'Y106' OR 'ZTSR' OR 'Y127' OR 'Y125' OR 'Y126' OR 'Y124' OR 'Y157' OR 'Y092' OR 'Y085' OR 'Y090' OR 'ZMZD'
OR 'Y215' OR 'Y214' OR 'Y111' OR 'ZC$D' OR 'ZAUD'.
up till here it is working on errors and when I add few more condition types to the case statement it is throwing the error.
I have to check for all the condition types out here.
How can I correct it? Is there a better way to do it?
thanks
SanthoshHi Santhosh,
I think that your CASE statement has a flaw. The line length of one of the lines is too large. You need to insert a carriage-return to shorten it (or press the button 'Pretty Printer').
The code would look nicer like this:[code] CASE wac-kschl.
WHEN 'ZRAT' OR 'ZAGR' OR 'ZRCR' OR 'Y098' OR 'Y007' OR 'ZREW'
OR 'Y106' OR 'ZTSR' OR 'Y127' OR 'Y125' OR 'Y126' OR 'Y124'
OR 'Y157' OR 'Y092' OR 'Y085' OR 'Y090' OR 'ZMZD' OR 'Y215'
OR 'Y214' OR 'Y111' OR 'ZC$D' OR 'ZAUD' OR 'Z001' OR 'Z002'
OR 'Z003' OR 'Z004' OR 'Z005' OR 'Z006' OR 'Z007' OR 'Z008'
OR 'Z009' OR 'Z010' OR 'Z011' OR 'Z012' OR 'Z013' OR 'Z014'.
Do your thing here
WRITE: / 'OK'.
WHEN OTHERS.
WRITE: / 'NOT OK'.
ENDCASE.[/code]If this will not work for you, you could try a different approach:[code]* Local definition
DATA:
var_list(1024).
Build variable string for checking
CONCATENATE 'ZRAT ZAGR ZRCR Y098'
'Y007 ZREW Y106 ZTSR'
'Y127 Y125 Y126 Y124'
'Y157 Y092 Y085 Y090'
'ZMZD Y215 Y214 Y111'
'ZC$D ZAUD'
INTO var_list
SEPARATED BY space.
Check if the correct value is supplied
IF var_list CS wac-kschl.
Do your thing here
WRITE: / 'OK'.
ENDIF.[/code]Hope this helps you a bit.
Regards,
Rob. -
Need help in this sql query to use Case Statement
hi All,
I have the below query -
SELECT DISTINCT OFFC.PROV_ID
,OFFC.WK_DAY
,CASE
WHEN OFFC.WK_DAY ='MONDAY' THEN 1
WHEN OFFC.WK_DAY ='TUESDAY' THEN 2
WHEN OFFC.WK_DAY ='WEDNESDAY' THEN 3
WHEN OFFC.WK_DAY ='THURSDAY' THEN 4
WHEN OFFC.WK_DAY ='FRIDAY' THEN 5
WHEN OFFC.WK_DAY ='SATURDAY' THEN 6
WHEN OFFC.WK_DAY ='SUNDAY' THEN 7
END AS DOW
,OFFC.OFFC_OPENG_TIME
,OFFC.OFFC_CLSNG_TIME
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID='0000600'
WITH UR;
this query is bringing results in 6 differnt rows with opening and closing time for each day separately. I want to generate the data in one row with each day having opening and closing time, so for 7 days, total 14 columns with opening and closing time. But i am not able to do that using case statement.
can somebody help me in achieving that.
thanks,
iamhereHi,
Welcome to the forum!
That's called a Pivot .
Instead of having 1CASE expression, have 14, one for the opening and one for the closing time each day, and do GROUP BY to combine them onto one row.
SELECT OFFC.PROV_ID
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_OPENG_TIME END) AS mon_opn
, MIN (CASE WHEN OFFC.WK_DAY ='MONDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS mon_cls
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_OPENG_TIME END) AS tue_opn
, MIN (CASE WHEN OFFC.WK_DAY ='TUESDAY' THEN OFFC.OFFC_CLSNG_TIME END) AS tue_cls
FROM GGDD.PROV_OFFC_HR OFFC
WHERE OFFC.PROV_ID = '0000600'
GROUP BY offc.prov_id
;This assumes there is (at most) only one row in the table for each distinct prov_id and weekday. If not, what do you want to do? Post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
The staement above works in Oracle 8.1 and up, but there's a better way (SELECT ... PIVOT) available in Oracle 11. What version are you using? (It's always a good idea to include this when you post a question.)
Edited by: Frank Kulash on Jan 6, 2011 8:22 PM -
Using case statement in merge when matched
Hi,
I want to use case statement in the when matched clause of merge statement to ensure that I update only those fields that are undated.
create table TEST1
NAME1 VARCHAR2(25),
NAME2 VARCHAR2(25),
ID NUMBER not null
create table TEST2
ID NUMBER not null,
ID2 NUMBER not null,
NAME1 VARCHAR2(25),
NAME2 VARCHAR2(25)
merge into test1 t1
using
test2 t2
ON (t1.id = t2.id)
when matched
then
case
when t1.name1 != t2.name1
then
update set t1.name1 != t2.name1
when t1.name2 != t2.name2
then
update set t1.name2 != t2.name2
else
null;
end
it does not work and raises invalid sql command. Any idea how can I do that?
Thanks.
Sajid
Edited by: 808255 on Nov 12, 2010 4:22 AMHi
In that case you would have to use multiple statements and you may as well just use UPDATE instead of MERGE. Also, are you sure that you aren't trying to to fix a problem that doesn't actually exist.
Think about where the execution time is going to come from...
I would be tempted to do 1 UPDATE like this...
UPDATE test1 t1
SET (t1.name1,
t1.name2) = (SELECT t2.name1,
t2.name2
FROM test2 t2
WHERE t1.id = t2.id
AND (t1.name1 != t2.name1
OR t1.name2 != t2.name2))If you get specific performance issue with this, then post an explain plan and trace and I'll have a look.
I don't this the cost of the update is going to be as great as you think.
Cheers
Ben -
Hi,
We have a date field in the form. I am validating date format as YYYY-MM-DD, validation works fine. But If user enters invalid date, how to validate date? For examples:
2006-02-31 It is an invalid date. How can i validate it.
If anybody have sample code, it will help me a lot.
thanks
Neopal.Hi Neopal,
You can use something like the following to test the date is valid, use the validation event on the <Field> which you want to validate to call a Rule something like this (not complete)..
<Rule name='isDateValid'>
<RuleArgument name='date'/>
<block>
<script>
var dateToTest = env.get('date');
var formatter = new java.text.SimpleDateFormat('YYYY-MM-DD');
Date validDate = formatter.parse(dateToTest); -
Can I use case statements in triggers?
I created this trigger, it works BUT I don't like those parentheses at the begining, I would like
to change those parentheses for case statements, well that is my question, can you use case statements in triggers, how you would translate the following in case statement?
FOR EACH ROW
WHEN ( (new.sgbstdn_levl_code = 'UG')
and
( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
OR
( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
(NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
(OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
==================================================================================================
CREATE OR REPLACE TRIGGER CC_STUD_WITHDRAWAL
AFTER UPDATE OR INSERT ON SATURN . SGBSTDN
FOR EACH ROW
WHEN ( (new.sgbstdn_levl_code = 'UG')
and
( (NEW. SGBSTDN_STST_CODE NOT IN ('GR','SA','AS','IS') )
OR
( (NEW. SGBSTDN_STST_CODE = 'IS' ) AND
(NEW. SGBSTDN_STYP_CODE IN ('N' , 'T' )) AND
(OLD. SGBSTDN_STST_CODE = 'AS' ) ) ) )
DECLARE
v_params gokparm.t_parameterlist;
event_code gtveqnm.gtveqnm_code%TYPE;
firstname spriden.spriden_first_name%TYPE;
lastname spriden.spriden_last_name%TYPE;
middlename spriden.spriden_mi%TYPE;
id spriden.spriden_id%TYPE;
CURSOR get_stud_name IS
SELECT
spriden_id ,
spriden_last_name ,
spriden_first_name ,
spriden_mi
FROM
saturn.spriden
WHERE spriden_pidm = :NEW.SGBSTDN_PIDM
AND spriden_change_ind IS NULL;
BEGIN
IF goksyst . f_isSystemLinkEnabled ( 'WORKFLOW' ) THEN
event_code := SUBSTR ( gokevnt.F_CheckEvent ( 'WORKFLOW' ,'CC_STUDENT_WITHDRAW' ),1,20);
OPEN get_stud_name ;
FETCH get_stud_name INTO id , lastname , firstname , middlename ;
CLOSE get_stud_name ;
----pass parameters to the event
v_params ( 1 ).param_value := 'CC_STUDENT_WITHDRAW' ;
v_params ( 2 ).param_value := '' ;
v_params ( 3 ).param_value := 'Student Withdrawal:' || lastname || ',' || firstname || ' ' ||
middlename ;
v_params ( 4 ).param_value := :NEW.sgbstdn_pidm ;
v_params ( 5 ).param_value := id ;
v_params ( 6 ).param_value := lastname ;
v_params ( 7 ).param_value := firstname ;
v_params ( 8 ).param_value := middlename ;
v_params ( 9 ).param_value := :NEW.sgbstdn_term_code_eff ;
v_params ( 10 ).param_value := :NEW.SGBSTDN_STST_CODE ;
v_params ( 11 ).param_value := :NEW.SGBSTDN_STYP_CODE ;
gokparm.Send_Param_List ( event_code , v_Params );
END IF;
END;
/You could delete a fair number of extraneous parentheses.
CREATE OR REPLACE TRIGGER cc_stud_withdrawal
AFTER UPDATE OR INSERT
ON saturn.sgbstdn
FOR EACH ROW
WHEN NEW.sgbstdn_levl_code = 'UG'
AND ( NEW.sgbstdn_stst_code NOT IN ('GR', 'SA', 'AS', 'IS')
OR ( NEW.sgbstdn_stst_code = 'IS'
AND NEW.sgbstdn_styp_code IN ('N', 'T')
AND OLD.sgbstdn_stst_code = 'AS')) -
Conditional Filters using case statements
Hello,
I have a table view which displays Total Quota and Theatre Quota. Against the Total Quota, there are 2 values - Rollover Revenue and Theatre Revenue. Against the Theatre Quota, there is only Theatre Revenue.
What I want to accomplish is to display only the Rollover Revenue Aggregated Quarterly number whenever there is a Total Quota number and not display the Theatre Revenue number
In the table view,
Year Name Quarter Name Quarter Name Sort Person Region Quota Name Quarterly Quota Credit Amount QTD Attainment Credit Type Name
YEAR-2012 QTR-1-2012 QTR-1-2012 750 Total Quota 6,128,500 5,492,081 89.62% Rollover Revenue Aggregated Quarterly
750 6,128,500 5,344,000 87.20% Theatre Revenue
QTR-2-2012 QTR-2-2012 750 Total Quota 5,922,500 5,890,264 99.46% Rollover Revenue Aggregated Quarterly
750 5,922,500 6,120,000 103.33% Theatre Revenue
QTR-3-2012 QTR-3-2012 750 Total Quota 5,716,500 0 0.00%
QTR-4-2012 QTR-4-2012 750 Total Quota 5,510,500 0 0.00%
I used an example in the following link:
http://oraclebizint.wordpress.com/2008/02/06/oracle-bi-ee-101332-conditional-filters-using-case-statements-in-filters/
and applied the example in my scenario:
CASE WHEN Quota."Quota Name" = 'Total Quota' THEN "Credit Type"."Credit Type Name" ELSE 'Dummy' END != 'Theatre Revenue'
I still get duplicate rows.
Thanks.Could you suggest any solutions for this problem where I can conditionally hide the number only for a certain type of data and not for all type of data?
Thanks. -
A relative synced my iphone with his laptop without me knowing. It had a passcode on the phone but the sync still worked. I have since found out he is quite IT knowledgeable and has been known to track other peoples phones that he wants to know information about. How is my data useful to him and can he restore this data on another iPhone and run it parallel to mine? I have had people send me messages which I have not received. These have been screen shot to me later including time and I have just not got them. I had 4 weeks worth of messages go missing from my phone..I know that he synced my phone because his work laptops I'd came up in my settings. Also if the above can be done can he change the settings on my actual phone and access my location without placing tracking software on my phone. Can someone please help here as I can't restore a backup to my phone for obvious reasons and refuse to change my number because of this loser.
Connect the device to the computer.
In iTunes, select the content desired to sync.
Sync.
This is all described in the User's Guide, reading it may be a good place to start. -
Query Tuning - using CASE statement in the WHERE clause - Duplicate Post
Duplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AMDuplicate Post by mistake.
Please check
Query Tuning - using CASE statement in the WHERE clause
Edited by: Chaitanya on Jun 9, 2011 2:45 AM
Edited by: Chaitanya on Jun 9, 2011 2:46 AM -
Using Case statement instead of IF in formula fields
Hi,
Can I use Case statement instead of IF in formula fields?If yes,please specify the syntax.
regards,
sunithaHi Sunitha,
You can surely use case statement instead of the If statement. The syntax for the case statement is :
Select [1 To n]
Case "Condition a", "Condition b":
"c"
Case "Condition d","Condition e":
"f"
Default:
Hope this helps you!
Regards,
Anindita
Maybe you are looking for
-
Hey guys, I've now got arch running on my air perfectly I think, except for a random loss of trackpad and keyboard input. It happens even with a usb keyboard. I'm not sure if the whole laptop is freezing or only the inputs stop functioning, I believe
-
Hi. How i can suppress the applet view status bar when deploying form6i on Web. Thanks. null
-
Solaris root password & installer
I have installed oracle solaris 11 exp, but : I have difficulties finding root password, have tried solaris & my user password but it's not going, during the installation I have used solaris passwrd for the partition manager and it worked, but no lat
-
User Exit M61X0001 won't activate
Hello all, I am trying to activate a user exit with enhancement M61X0001 and continually receive the following error message: Parameter LSM not in version 0015 of tp configuration Message no. XT465 Can anyone tell me what this means? I'm wondering i
-
Accessing Sub Calendars in via HTTP Web Calendar
Hi, I'm trying to work out how to display all of my calendars on the web calendar interface in OS X 10.5.5 I am accessing the server : http://diary.local which give me a login prompt, I successfully log in and then go to Calendar, it says please wait