Using Field/Column Date Value In Case Statement
I have code that the first part works (the part that evaluates null). However, it appears the second part doesn't work. The error I get is:
Data Value out of range
Can you use the a table column value in a Case statement? What I'm trying to do is: where all mbr06..values are 12/31/9999, then null; if mbr06.. values are equal to or less than today's date, then put the value in mbr02.mbr02_cancel_proc_date..
Note, the table MBR02 does have dates that go back as far as 11/17/1858..could that be an issue?
Thanks for any assistance..
cast((case
when mbr06.mbr06_exp_date = to_date('31-dec-9999') then null
when mbr06.mbr06_exp_date <= sysdate then mbr02.mbr02_cancel_proc_date
The error is due to the CAST, not to the CASE.
Cause: Value from cast operand is larger than cast target size.Post at least the whole cast ...
Max
http://oracleitalia.wordpress.com
Similar Messages
-
Issue with referencing Presentation variables(Date cols) in Case statement
Hi,
I m trying to reference presentation variables created on a Date column in the case statement of one of the request's columns as shown below:
case when "- Quote Details"."Creation Date" between '@{from}{1999-1-1}' and '@{until}{2999-1-1}' then "- Quote Metrics"."# of Quotes" end
I m getting a view display error with the below error message:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1861, message: ORA-01861: literal does not match format string at OCI call OCIStmtExecute
SQL Issued: SELECT "- Quote Types"."Level2 Name" saw_0, case when "- Quote Details"."Creation Date" between '4/1/2009' and '4/15/2009' then "- Quote Metrics"."# of Quotes" end saw_1 FROM "(Unity) Quotes Catalog" WHERE "- Quote Details"."Creation Date" BETWEEN timestamp '2009-04-01 00:00:00' AND timestamp '2009-04-15 00:00:00' ORDER BY saw_0
When I created the prompt on the date field I put the following formula in the prompt:
cast("- Time".Day as DATE)
When I apply a filter on the request using these variables it works fine.
If anyone has faced this kind of issue earlier and have a resolution, please help me out.
Thanks,
KartikThanks Goran!!
I've created prompts by selecting columns from the logical tables (i.e. I've selected 2 different cols of datatype DATE...inorder to assign 2 presentation variables).
Yes I m using calendar widget for prompts.
I haven't included any filter in my report. I m trying to display a metric when it satisfies the case statement.
I will defintley go through the blogs you mentioned for better understanding.
Thanks,
Kartik
Query fired on physical db:
WITH
SAWITH0 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5
from
(select T192898.QLS_FIRST_ACAP_DT as c1,
TO_DATE('3/2/2009','mm/dd/yyyy') as c2,
TO_DATE('4/29/2009','mm/dd/yyyy') as c3,
T188666.LEVEL2_NAME as c4,
T188666.ID as c5,
ROW_NUMBER() OVER (PARTITION BY T188666.ID, T192898.QLS_FIRST_ACAP_DT ORDER BY T188666.ID ASC, T192898.QLS_FIRST_ACAP_DT ASC) as c6
from
XXSLS_GBL_QTE_TYPES_V T188666,
XXSLS_GBL_QTE_DTL_F T192898
where ( T188666.ID = T192898.QUOTE_TYPE_ID )
) D1
where ( D1.c6 = 1 ) ),
SAWITH1 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3
from
(select count(distinct T192898.QUOTE_HEADER_ID) as c1,
T188666.LEVEL2_NAME as c2,
T188666.ID as c3,
ROW_NUMBER() OVER (PARTITION BY T188666.ID ORDER BY T188666.ID ASC) as c4
from
XXSLS_GBL_QTE_TYPES_V T188666,
XXSLS_GBL_QTE_DTL_F T192898
where ( T188666.ID = T192898.QUOTE_TYPE_ID )
group by T188666.ID, T188666.LEVEL2_NAME
) D1
where ( D1.c4 = 1 ) ),
SAWITH2 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3
from
(select case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end as c1,
case when SAWITH0.c1 between SAWITH0.c2 and SAWITH0.c3 then SAWITH1.c1 else NULL end as c2,
case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end as c3,
ROW_NUMBER() OVER (PARTITION BY case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end , case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end ORDER BY case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end ASC, case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end ASC) as c4
from
SAWITH0 full outer join SAWITH1 On SAWITH0.c5 = SAWITH1.c3
) D1
where ( D1.c4 = 1 ) )
select SAWITH2.c1 as c1,
SAWITH2.c2 as c2
from
SAWITH2
order by c1 -
Navigate Value Interaction - Case Statements
Hi,
I am having problems using the navigate value interaction feature in OBIEE. The columns I am using to navigate contain case statement bin filters, is it not possible to use value interaction on these type of fields?
For example bin grouping are created in both reports and are identical but the interaction does not work
. TIMESTAMPDIFF(SQL_TSI_MONTH,CURR... is between 0 and 6
. TIMESTAMPDIFF(SQL_TSI_MONTH,CURR... is between 7 and 12
Can anyone advise a workaround other than creating the column in the rpd.
ThanksI gave a detailed decision in a similar topic Obiee Report Help
-
Update column data to Upper Case in parent and child table
Hi ,
I am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
when updating parent row:
ORA-02292: integrity constraint (XXXXXXXXXXXXXX_FK) violated - child record found
When updatng corresponding child row:
ORA-02291: integrity constraint (XXXXXXXXXXXXXXXX_FK) violated - parent key not found
how can i update on both the places ?
Regards,
AAI am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
Why do you need to do that?
That is just ONE of several questions you should answer before you start modifying your data.
1. What is your 4 digit Oracle version? (result of SELECT * FROM V$VERSION)
2. If both values are the same case what difference does it make what that case is?hen you don't need to alter your original data.
3. What is the source of the column values you are using now? If you change your data to upper case it will no longer be identical to the source data.
4. What is your plan for enforcing future values to be stored in UPPER case? Are you going to use a trigger? Have you written and tested such a trigger to see if it will even work the way you expect?
5. Why aren't you using a surrogate key instead of a 'business' data item? You have just demonstrated one reason why surrogate keys can be useful: their actual value is NOT important.
You should reexamine your problem and architecture and consider other alternatives.
One alternative is to add a new 'surrogate key' column to use as the primary key. Just create a new sequence and use a trigger to populate the new column. Your current plans will require a trigger to perform the case conversion so instead of the just use the trigger to provide the value.
If the change is being done to facilitate searching you could just add a VIRTUAL column UPPER_MY_COLUMN and index that instead. Then you could search on that new virtual column and the data values would still be identical to the original data source. -
Using Presentation variables..along with case statements..
Hi All.
I have a issue using presentation variable along with CASE statements. My approach is
1) I have a dashboard prompt, which is being set as Presentation variable.
Based on the value selected in prompt, for ex the values of prompt can be 'ABC' and 'DEF'.
I have a calculated column, the calculation goes this way...
The forumal is
CASE WHEN @{Presentation Variable Name} = 'ABC' THEN xxxxxxxxxx ELSE IF @{Presentation Variable Name} = 'DEF' END. It gives error of "no table being referenced"..
Is this is the right approach??
Can i get the values of variable in a column formula, so that a column can have values selected in prompt?
Can anybody pls help me here..
Thanks in advance...Hi
Thanks for the quick response..
I agree to ur point..
But the requirement is
Based on the value of the prompt I need to switch the calculation in one of the formula area of one column..
If Prompt value is ABC then one kind of calculation in Fx and If the prompt value is DEF then one kind of calculation in the same Fx..
How can I acheive this?
Thanks in advance.. -
SQL Expression Field - Combine Declared Variable With Case Statement
Hello All, I have been using Crystal & Business Objects for a few months now and have figured out quite a bit on my own. This is the first real time I have struggled with something and while I could do this as a Formula Field I would like to know how to do this as a SQL Expression. Basically I want to create a SQL Expression that uses a CASE statement but I wanted to make the code a little more efficient and employ a variable to hold a string and then use the variable in the CASE statement. The expression editor accepts the CASE statement OK but I don't know how to declare the variable. Please assist with the syntax?
This is what I have:
CASE
WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Hu2019 THEN u2018Hedgeu2019
WHEN u201CDatabaseu201D.u201DFieldu201D = u2018Pu2019 THEN u2018PVIu2019
ELSE u2018Noneu2019
END
This is what I want:
DECLARE strVar AS VARCHAR(25)
strVar = u201CDatabaseu201D.u201DFieldu201D
CASE
WHEN strVar = u2018Hu2019 THEN u2018Hedgeu2019
WHEN strVar = u2018Pu2019 THEN u2018PVIu2019
ELSE u2018Noneu2019
ENDHi Todd,
Please use the following for loop; your problem will be solved.
Local StringVar str := "";
Local NumberVar strLen := Length ({Database.Field});
Local NumberVar i;
For i := 1 To strLen Do
if {Database.Field} <i> = "H" then str := "Hedge"
else if {Database.Field} <i> = "P" then str := "PVI"
else str := "None"; exit for
str
Let me know once done!
Thank you,
Ashok -
Wildcard value in case statement
Hi,
How would I use a wildcard value in my case statement. I evaluate a string value of numbers and try to do this "1234***" but it doesn't work. "***" represents any 3 number.
Please advise.
Thanks
dphan128You could mark one of the cases as "Default", and that case will execute when no others match. If you want to explicitly run that case only if the first 4 numbers are "1234", then you need to pre-process the string.
See here for the same exact question. -
COLUMN DATA VALUE EXCEEDS-REJECTED WHILE BULK LOADING
hi
am having a table like
CREATE TABLE SMLC_CELLDATA
MCC NUMBER,
MNC NUMBER,
LAC VARCHAR2(10 BYTE),
CELL_ID VARCHAR2(10 BYTE),
CELL_NAME VARCHAR2(500 BYTE),
LAT FLOAT(20),
LON FLOAT(20),
ORIENTATION NUMBER,
OPENING NUMBER,
RANGE NUMBER,
BSIC NUMBER,
ARFCN NUMBER,
HANDOVER VARCHAR2(4000 BYTE),
EIRP NUMBER,
ENVIRONMENT VARCHAR2(50 BYTE)
TABLESPACE SYSTEM
PCTUSED 40
PCTFREE 10
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 64K
MINEXTENTS 1
MAXEXTENTS 2147483645
PCTINCREASE 0
FREELISTS 1
FREELIST GROUPS 1
BUFFER_POOL DEFAULT
LOGGING
NOCACHE
NOPARALLEL;WHEN I TRY TO BULK LOAD DATA IN TO THIS TABLE CERTAIN ROWS WERE REJECTED. AND IT SAYS COLUMN HANDOVER VALUE EXCEEDS THE LIMIT.
BUT THE DATA IS
404-80-101-1021 404-80-101-1022 404-80-101-1023 404-80-101-1101 404-80-101-1103 404-80-101-1131 404-80-101-1132 404-80-101-1133 404-80-101-1151 404-80-101-1153 404-80-101-1161 404-80-101-1163 404-80-101-1322 404-80-101-1392 404-80-101-1393 404-80-120-18312
WHICH IS OF 256 BYTES. HOW COME IT CAN REJECT IT..?
AEMUNATHAN
Edited by: Aemunathan on Sep 26, 2008 6:13 PMthe bad file contains
404 80 101 1102 110_Hotel_Madura_H2 10.79805556 78.68110833 120 60 3000 38 77 404-80-101-1021 404-80-101-1022 404-80-101-1023 404-80-101-1101 404-80-101-1103 404-80-101-1131 404-80-101-1132 404-80-101-1133 404-80-101-1151 404-80-101-1153 404-80-101-1161 404-80-101-1163 404-80-101-1322 404-80-101-1392 404-80-101-1393 404-80-120-18312 52 u
404 80 105 9012 901_Tansi_Kumbakonam_H2 10.96108056 79.39166667 120 60 3000 34 75 404-80-105-9011 404-80-105-9013 404-80-105-9032 404-80-105-9051 404-80-105-9052 404-80-105-9091 404-80-105-9092 404-80-105-9093 404-80-105-9132 404-80-105-9133 404-80-105-9181 404-80-105-9183 404-80-105-9233 404-80-105-9282 404-80-121-17013 404-80-121-17033 52 u
404 80 107 13012 1301_Attur_H2 11.59705556 78.59446944 100 60 3000 32 77 404-80-107-13011 404-80-107-13013 404-80-107-13023 404-80-107-13041 404-80-107-13043 404-80-107-13112 404-80-107-13113 404-80-107-13121 404-80-107-13122 404-80-107-13123 404-80-107-13441 404-80-107-13443 404-80-107-13471 404-80-107-13473 404-80-232-32842 404-80-232-32843 52 u
404 80 107 13303 1330_Omallur_H2 11.73888889 78.04583056 210 60 3000 36 69 404-80-107-13101 404-80-107-13102 404-80-107-13241 404-80-107-13301 404-80-107-13302 404-80-107-13313 404-80-107-13322 404-80-107-13352 404-80-107-13423 404-80-204-4051 404-80-204-4052 404-80-204-4053 404-80-204-4072 404-80-204-4073 404-80-207-7201 404-80-207-7203 52 u
404 80 107 13423 1342_Yercaud_Support_H1 11.77083056 78.19860833 240 60 3000 32 63 404-80-107-13071 404-80-107-13072 404-80-107-13073 404-80-107-13091 404-80-107-13092 404-80-107-13093 404-80-107-13102 404-80-107-13132 404-80-107-13171 404-80-107-13173 404-80-107-13301 404-80-107-13302 404-80-107-13303 404-80-107-13311 404-80-107-13313 404-80-107-13322 404-80-107-13351 404-80-107-13352 404-80-107-13353 404-80-107-13421 404-80-107-13422 404-80-136-36102 404-80-204-4021 404-80-204-4031 404-80-204-4051 404-80-204-4073 404-80-204-4261 404-80-204-4263 52 u
404 80 109 15152 1515_Paramathy_Exg_H1U 11.15138889 78.02471944 200 60 3000 32 71 404-80-109-15141 404-80-109-15142 404-80-109-15143 404-80-109-15151 404-80-109-15153 404-80-109-15251 404-80-109-15253 404-80-109-15311 404-80-109-15312 404-80-109-15313 404-80-109-15322 404-80-109-15401 404-80-109-15403 404-80-205-5232 404-80-207-7531 404-80-207-7533 52 u
404 80 109 15172 1517_Andalurgate_H1 11.44916667 78.15916667 80 60 3000 39 68 404-80-109-15011 404-80-109-15053 404-80-109-15161 404-80-109-15163 404-80-109-15171 404-80-109-15173 404-80-109-15181 404-80-109-15182 404-80-109-15183 404-80-109-15193 404-80-109-15261 404-80-109-15333 404-80-109-15421 404-80-109-15430 404-80-109-15463 404-80-207-7101 404-80-207-7102 404-80-207-7162 52 u
404 80 112 20012 2001_Attur_TE_H2D 11.59705556 78.59446944 85 60 1500 32 77 404-80-107-13121 404-80-107-13122 404-80-107-13123 404-80-112-20011 404-80-112-20013 404-80-112-20022 404-80-112-20023 404-80-112-20141 404-80-112-20143 404-80-112-20153 404-80-112-20231 404-80-112-20233 404-80-112-20251 404-80-112-20253 404-80-232-32842 404-80-232-32843 52 u
404 80 115 12222 1222_Venkateswara_Ngr_H1 11.11722222 79.66166667 210 60 3000 35 71 404-80-115-12221 404-80-115-12223 404-80-115-12231 404-80-115-12232 404-80-115-12241 404-80-115-12242 404-80-115-12243 404-80-115-12253 404-80-115-12261 404-80-115-12262 404-80-115-12311 404-80-115-12312 404-80-115-12313 404-80-115-12321 404-80-115-12353 404-80-115-12413 404-80-115-12471 52 u
404 80 121 17011 1701_Eravancheri_H1 10.93305556 79.55416667 40 60 3000 34 82 404-80-105-9112 404-80-105-9113 404-80-105-9163 404-80-105-9742 404-80-115-12242 404-80-115-12243 404-80-115-12252 404-80-115-12403 404-80-115-12473 404-80-121-17012 404-80-121-17013 404-80-121-17041 404-80-121-17043 404-80-121-17131 404-80-121-17133 404-80-121-17182 52 u
404 80 121 17442 1744_Exg_Pattukkottai_H2 10.42666667 79.31891667 130 60 3000 32 76 404-80-121-17111 404-80-121-17113 404-80-121-17162 404-80-121-17401 404-80-121-17402 404-80-121-17403 404-80-121-17422 404-80-121-17423 404-80-121-17431 404-80-121-17433 404-80-121-17441 404-80-121-17443 404-80-121-17461 404-80-121-17472 404-80-121-17522 404-80-121-17523 52 u
404 80 130 30022 Coonoor_MW_2 11.34527778 76.81027778 270 65 3000 47 68 404-80-130-30041 404-80-130-30051 404-80-130-30151 404-80-130-30012 404-80-130-30031 404-80-130-30032 404-80-130-30033 404-80-130-30021 404-80-130-30052 404-80-130-30152 404-80-130-30153 404-80-130-30011 404-80-130-30211 404-80-130-30162 404-80-130-30163 404-80-130-30013 404-80-130-30361 404-80-130-30023 404-80-130-30363 404-80-130-30251 404-80-130-30253 52 u
404 80 130 30093 Forest_Land_Ooty_3 11.395 76.70277778 270 65 3000 44 75 404-80-130-30433 404-80-130-30182 404-80-130-30142 404-80-130-30143 404-80-130-30103 404-80-130-30091 404-80-130-30092 404-80-130-30082 404-80-130-30083 404-80-130-30053 404-80-130-30321 404-80-130-30183 404-80-130-30422 404-80-130-30283 404-80-130-30423 404-80-130-30413 404-80-130-30432 404-80-130-30431 52 u
404 80 130 30163 Vandhisolai_3 11.37222222 76.81861111 220 65 3000 47 74 404-80-130-30161 404-80-130-30162 404-80-130-30153 404-80-130-30011 404-80-130-30012 404-80-130-30151 404-80-130-30073 404-80-130-30022 404-80-130-30033 404-80-130-30051 404-80-130-30361 404-80-130-30013 404-80-130-30303 404-80-130-30383 404-80-130-30023 404-80-130-30203 404-80-130-30253 52 u
404 80 132 32731 Collectorate_IBS TNJ 10.81458 79.60622 0 65 3000 47 74 404-80-121-17071 404-80-121-17091 404-80-121-17093 u
404 80 134 34741 Parambikulam_IBS_1 10.390417 76.774889 0 65 3000 42 63 404-80-132-32443 m
404 80 134 34751 TNG_Palayam_IBS2_1 10.390417 76.774889 0 65 1000 40 63 404-80-134-34141 404-80-134-34651 404-80-134-34652
404 80 149 49011 Tirunelveli MSC Switch 8.72777 77.7044 0 360 200
404 80 149 49012 Tirunelveli MSC Switch 8.72777 77.7044 0 360 200 m
404 80 166 6611 Ranga_Pilllai BSNL Pondy Exchange building 11.56 79.5 0 360 200 404-80-160-60171 m
404 80 204 4261 426_Old_Suramangalam_H2 11.67055556 78.10999722 0 60 3000 39 70 404-80-107-13072 404-80-107-13073 404-80-107-13302 404-80-107-13423 404-80-204-4051 404-80-204-4071 404-80-204-4072 404-80-204-4073 404-80-204-4251 404-80-204-4253 404-80-204-4262 404-80-204-4263 404-80-204-4270 404-80-204-4753 404-80-204-4773 404-80-204-4910 52 u
404 80 205 5232 523_Kodumudi_H2 11.07916667 77.87999722 120 60 3000 33 69 404-80-109-15142 404-80-109-15152 404-80-109-15382 404-80-109-15412 404-80-109-15413 404-80-114-11103 404-80-114-11201 404-80-114-11203 404-80-205-5231 404-80-205-5233 404-80-205-5251 404-80-205-5252 404-80-205-5571 404-80-205-5572 404-80-206-6081 404-80-207-7552 52 u
404 80 205 5392 539_V.P.Palayam_Erode_H1 11.29610833 77.66944444 120 60 3600 33 73 404-80-205-5593 404-80-205-5591 404-80-205-5493 404-80-205-5492 404-80-205-5393 404-80-205-5391 404-80-205-5283 404-80-205-5281 404-80-205-5163 404-80-205-5161 404-80-205-5133 404-80-205-5123 404-80-110-16762 404-80-110-16651 404-80-110-16612 404-80-110-16611 52 u
404 80 232 32842 Thalaivasal_2 11.5698056 78.7496389 120 60 3000 43 80 404-80-107-13042 404-80-107-13441 404-80-107-13471 404-80-107-13473 404-80-2003-22253 404-80-232-32841 404-80-232-32843 u
each row ends with "u"
Edited by: Aemunathan on Sep 26, 2008 9:02 PM -
How to use Oracle Table Type values in Select Statement.
Hi,
I am fetching initial set of values into Oracle Table of Records Type and want to use list of values in the Select statement.
For example, try something like the following:
TYPE t_record IS RECORD (
ID TABLEA.ID%type,
NO TABLEA.NO%type,
v_record t_record;
TYPE t_table IS TABLE OF v_record%TYPE;
v_table t_table;
-- Code to populate the values in v_table here.
SELEC ID,NO, BULK COLLECT INTO <some other table variabes here> FROM TABLEA
WHERE ID IN v_table(i).ID;
I want to know how to use the values from Oracle Table Type in the Select Statement.Something like this:
create or replace type t_record as object (
id number,
no number
CREATE or replace type t_table AS TABLE OF t_record;
set serveroutput on
declare
v_table t_table := t_table();
v_t1 t_table := t_table();
begin
v_table.extend(1);
v_table(1).ID := 1;
v_table(1).No := 10;
v_table.extend(1);
v_table(2).ID := 2;
v_table(2).ID := 20;
SELEC t_record (ID,NO) BULK COLLECT INTO v_t1
from TableA
FROM TABLEA
WHERE ID IN (select t.ID from table(v_Table) t);
for i in 1..v_t1.count loop
dbms_output.put_line(v_t1(i).ID);
dbms_output.put_line(v_t1(i).No);
end loop;
end;
/Untested!
P;
Edited by: bluefrog on Mar 5, 2010 5:08 PM -
To use Boolean function in DECODE or CASE statement
Hi all
I have a scenario where i need to use a boolean function inside DECODE statement. When i tried this way iam getting "ORA-06553: PLS-382: expression is of wrong type".
I doubt whether i can use boolean function inside DECODE or not?
My query will be like this:
select decode(my_fuction( ),'TRUE',1,'FALSE',0) from dual;
Any help is highly appreciated.
Thanks
SriramOverloaded functions must differ by more than their
return type . At the time that the overloaded
function is called, the compiler doesn't know what type
of data that function will return. The compiler cannot,
therefore, determine which version of the function to
use if all the parameters are the same. -
I am trying to use cellular data and states connection failed. What do I need to do to fix this?
ThanksHi there April3939,
You may find the troubleshooting steps in the article below helpful.
iPad (Wi-Fi + Cellular Models): Troubleshooting a cellular data connection
http://support.apple.com/kb/TS4249
-Griff W. -
How to eliminate NULL values from case statement?
I have the following query where I am trying to eliminate the NULL record. How can I do this? My query:
select
AttendedSchoolLast3Months = case
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'BC349A1E-65A1-4497-A38A-116C83B2028F' then 2 --No
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'A529C643-60A7-4D79-AC67-1A8F70791934' then 1 --Yes
end
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A'
And the result currently is:
AttendedSchoolLast3Months
1
NULL
When I ran this query:
select distinct --attendedschoollast3months
d.*
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
--join [education_level] e (nolock) on e.[EducationLevel] = udl1.[description]
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A'
I get this:
event_log_id people_id group_profile_id actual_date test_header_id test_setup_details_id test_domains_info_id question_caption question_code test_details_answers_id update_log_id test_details_id numeric_value scrnval_id picklist_value remarks narrative test_setup_details_answers_id is_checked date_value details_type_code test_setup_answers_caption test_setup_answers_order test_setup_answers_value output_code answers_category_id answers_category answers_category_code
24E8F88F-9648-4714-9394-D5A3F642C0F0 7A9ACEE4-ABD5-4905-A54E-659A81048A1A NULL 2013-09-26 17:00:00.000 24E8F88F-9648-4714-9394-D5A3F642C0F0 67CDCF44-6308-4E15-8543-3C85DE4C6D4D NULL Attended school in the last 3 months NULL 1BB75044-A65C-4464-ADB9-0CA991019907 7CDD1A4F-41F4-403C-A85E-7FF51B761FF0 3F04BBFF-8DE9-4283-842F-E53A536E3E46 NULL AA5639E4-E60C-473F-9B72-354472C11F5B A529C643-60A7-4D79-AC67-1A8F70791934 NULL NULL 5979600C-B4E6-42DF-BF45-8AFF15ACDD7D 0 NULL PICKLIST Click here for list 1 NULL NULL NULL NULL NULL
24E8F88F-9648-4714-9394-D5A3F642C0F0 7A9ACEE4-ABD5-4905-A54E-659A81048A1A NULL 2013-09-26 17:00:00.000 24E8F88F-9648-4714-9394-D5A3F642C0F0 EBDFBCA5-6E57-4907-9DEF-A1E118F3AB2D NULL Highest grade completed NULL 8F7F4644-4E67-4821-B0FC-A192389F994D 7CDD1A4F-41F4-403C-A85E-7FF51B761FF0 F6C59E67-EC74-4F0C-8EE8-AB372F22255D NULL 4536DD06-871D-4FA7-BA8A-552DB2CA59BC D77F0CAB-505E-4838-AECE-01BAAE8B8EB2 NULL NULL E7C9ECB7-7B40-4115-A6DB-BC752116D68D 0 NULL PICKLIST Click here for list 1 NULL NULL NULL NULL NULL
Ryan DHi,
what I understood from above is that u want to filter NULL records and want to display only not null records. Try below query.
SELECT * FROM(select
AttendedSchoolLast3Months = case
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'BC349A1E-65A1-4497-A38A-116C83B2028F' then 2 --No
when d.scrnval_id = 'AA5639E4-E60C-473F-9B72-354472C11F5B' and d.picklist_value = 'A529C643-60A7-4D79-AC67-1A8F70791934' then 1 --Yes
end
From [evolv_cs].[dbo].[test_header] [test_header_rv] WITH (NOLOCK)
CROSS APPLY [dbo].[fn_getTestSetupFormDetails](null, [test_header_rv].[test_setup_header_id]) AS [test_header]
CROSS APPLY [dbo].[fn_getTestSetupFormDetails]([test_header].[test_setup_details_id], null) AS [test_details]
JOIN [evolv_reports].[dbo].[test_details_answers_expanded_view] d WITH (NOLOCK) ON
[test_header_rv].[test_header_id] = d.[test_header_id]
AND [test_details].[test_setup_details_id] = d.[test_setup_details_id]
join [user_defined_lut_rv] udl1 with(nolock) on udl1.[user_defined_lut_id] = d.picklist_value
join people_rv p (nolock) on d.people_id = p.people_id
where d.actual_date between '9/1/13' and '9/30/13'
and d.people_id = '7A9ACEE4-ABD5-4905-A54E-659A81048A1A' ) AWHERE AttendedSchoolLast3Months IS NOT NULLTry this query.
Thanks Shiven:) If Answer is Helpful, Please Vote -
Naming the evaluated case statement field with concatenating input variable value
Hi,
I am trying to add the input variable value to case statement evaluated field like below query:
declare @Year varchar(4)
select ProductCode,datepart(mm,Date) MonthValue,
case when datepart(mm,Date) = 1 then sum(Price) else 0 END AS Jan+@Year,
case when datepart(mm,Date) = 2 then sum(Price) else 0 END AS Feb+@Year,
case when datepart(mm,Date) = 3 then sum(Price) else 0 END AS Mar+@Year,
case when datepart(mm,Date) = 4 then sum(Price) else 0 END AS Apr+@Year,
case when datepart(mm,Date) = 5 then sum(Price) else 0 END AS May+@Year,
case when datepart(mm,Date) = 6 then sum(Price) else 0 END AS Jun+@Year,
case when datepart(mm,Date) = 7 then sum(Price) else 0 END AS Jul+@Year,
case when datepart(mm,Date) = 8 then sum(Price) else 0 END AS Aug+@Year,
case when datepart(mm,Date) = 9 then sum(Price) else 0 END AS Sep+@Year,
case when datepart(mm,Date) = 10 then sum(Price) else 0 END AS Oct+@Year,
case when datepart(mm,Date) = 11 then sum(Price) else 0 END AS Nov+@Year,
case when datepart(mm,Date) = 12 then sum(Price) else 0 END AS Dec+@Year
from Sales_Imports where datepart(yyyy,Date) = @Year
group by ProductCode, datepart(mm,Date)
Please help me any other way as this is not working...
Thanks,
Srinicreate table Sales_Imports (ProductCode int, Price int, [date] date)
insert into Sales_Imports values
(1,10,'1/1/2014'),(1,109,'2/1/2014'),(1,10,'1/1/2014'),(1,109,'12/1/2014'),
(2,10,'1/1/2014'),(2,109,'2/1/2014'),(2,10,'10/1/2014'),(2,109,'12/1/2014')
declare @Year varchar(4)='2014'
DECLARE @MaxCount INT, @SQL NVARCHAR(max) ,@i INT;
Set @MaxCount = 12
SET @i = 0;
SET @SQL = '';
WHILE @i < @MaxCount
BEGIN
SET @i = @i + 1;
SELECT @SQL = @Sql + ', SUM(CASE WHEN datepart(mm,[Date]) = ' + cast(@i AS NVARCHAR(10)) + ' THEN Price Else 0 END) AS ' +Left(DateName(month,Dateadd(month,@i-1,0)) ,3)+@Year
END
SET @SQL = N' SELECT ProductCode, datepart(mm,Date) MonthValue ' + @SQL
+ N' FROM Sales_Imports
where datepart(yyyy,Date) ='+ @Year + N'group by ProductCode, datepart(mm,Date)
Order by ProductCode, datepart(mm,Date)';
--PRINT @SQL;
execute (@SQL);
--Or your original one
declare @Year varchar(4)
Set @Year ='2014'
declare @SQL Nvarchar(4000)
SET @SQL=
N' select ProductCode,datepart(mm,Date) MonthValue,
case when datepart(mm,Date) = 1 then sum(Price) else 0 END AS [jan' +@year+'],
case when datepart(mm,Date) = 2 then sum(Price) else 0 END AS [feb' +@year+'],
case when datepart(mm,Date) = 3 then sum(Price) else 0 END AS [Mar'+@year+'],
case when datepart(mm,Date) = 4 then sum(Price) else 0 END AS [Apr'+@year+'],
case when datepart(mm,Date) = 5 then sum(Price) else 0 END AS [May'+@year+'],
case when datepart(mm,Date) = 6 then sum(Price) else 0 END AS [june'+@year+'],
case when datepart(mm,Date) = 7 then sum(Price) else 0 END AS [july'+@year+'],
case when datepart(mm,Date) = 8 then sum(Price) else 0 END AS [Aug'+@year+'],
case when datepart(mm,Date) = 9 then sum(Price) else 0 END AS [Sep'+@year+'],
case when datepart(mm,Date) = 10 then sum(Price) else 0 END AS [Oct'+@year+'],
case when datepart(mm,Date) = 11 then sum(Price) else 0 END AS [Nov'+@year+'],
case when datepart(mm,Date) = 12 then sum(Price) else 0 END AS [Dec'+@year+']
from Sales_Imports where datepart(yyyy,Date) = ' + @Year +N' group by ProductCode, datepart(mm,Date)'
--print @Query
Execute (@SQL)
drop table Sales_Imports -
Using a comparison to NULL in a CASE statement
Hi, please could anybody advise me if it is OK to use comparison to NULL in a CASE statement. Alternatively, will a NULL be accepted in a to_number function giving a result of a NULL in the number variable?
I have a list of varchar2 values which will either be a number, be equal to '95%' or be NULL. I need to translate that to a number column, removing the % from 95%.
I would like to know if the syntax below is allowed:
CASE vPurity
WHEN NULL THEN
nPurity = '';
WHEN '95%' THEN
nPurity := 95;
ELSE
nPurity := TO_NUMBER(vPurity);
END CASE;
Many thanks.robust
adj.
1. Full of health and strength; vigorous.
2. Powerfully built; sturdy. See Synonyms at healthy.
3. Requiring or suited to physical strength or endurance: robust labor.
4. Rough or crude; boisterous: a robust tale.
5. Marked by richness and fullness; full-bodied: a robust wine.
By saying "Robust" you are saying that DECODE is somehow stronger or better than CASE. This is not the case (scuse the pun) as CASE is more flexible than DECODE and can be easier to read in the code. CASE also handles non-equality comparisons far easier than can be done in DECODE. -
Date formats for SQL statements used by recordset object
Hi,
Date formatting appears to be quite problematic for Business One. I did a forum search for date issues and I don't think I saw any of them with an "answered" status. I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005. I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine. We don't have a problem as long as our machines are localized as USA.
I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field. So this is a date that is not entered by the user. The result of this function is consistent with the localization parameters on my machine. We have two other date fields on the form where the user must type in the date.
As a test, I changed my machine to the UK parameters. I then set up the language parameters of Business One for English(United Kingdom). I changed the date format specifications in Business One so that its format is dd/mm/yy. I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy. I then typed in the two other dates in the same format and added the record to the database. The form's table is user-defined.
I dismissed the form then brought it back up loaded with the new record. The date that was entered by the function appeared in USA format (mm/dd/yy). The dates that were typed in appeared in the Business One format (dd/mm/yy). This of course is not consistent.
When I looked at what got into the database, the formats were the opposite. Weird! To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function. It didnt matter what format I used for the WHERE clause, the record came up. Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
Thanks,
MikeIan,
Here's what I'm concerned about: Im using the date in a WHERE clause.
Assume the date is Aug 3, 2007.
"SELECT * FROM Table WHERE StartDate > 8/3/2007"
OR
"SELECT * FROM Table WHERE StartDate > 3/8/2007"
If the client machine is set up as USA, the today function will provide the date as formatted in the first query. If the database server is setup as lets say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
If the client machine is set up as UK, the today function will provide the date as formatted in the second query. If the database server is setup as lets say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
In both cases it would be wrong.
I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine. I need to then be able to concatenate those date parts for the WHERE clause so that the localization specifications of the database server dont matter.
Thanks,
Mike
Maybe you are looking for
-
How do you delete a website from "popular" in Safari?
How do you delete a website link from "popular" in Safari?
-
Screen Saver Photo Slide Show...
...Hello... This used to work but for some reason it doesn't any more. Whenever I go to the screen saver preferences and choose a folder full of pictures to use as a photo slide show screen saver, it says 'folder contains no pictures'. However, is DO
-
Help for using FM SO_NEW_DOCUMENT_ATT_SEND_API1
hi ,... i need help in putting a new line in the attachment which can be sent by using the FM SO_NEW_DOCUMENT_ATT_SEND_API1. for a quick reference please check out program:RSSOAPIS and let me know as to how can i add a new line in the attach file
-
In all the tabs written the same thing
In all the tabs written the same thing it says: "התחברות..." i try to reinstall firefox but the problem stays
-
Placing RGB inDesign pages results in CMYK. WHY???
Hi There may well be other threads on this, but I've trawled through the forum and can only find similar stuff, nothing that actually addresses this issue. If there's already something on it then I apologise. I'm making a presentation for screen usin