Doubt in case statement
in my rpd i got two columns a and b
both have the below mentioned logic
cloumn A : PREIOD <= 20 THEN 'No' ELSE 'Yes' END
column B: PREIOD >20 THEN ‘Yes’ ELSE ‘No’ END
what is the diffrence between these two logic can any one help me with a small example please
no diffrence as such.Both will populate same values.what is your requirement?
cloumn A : PREIOD <= 20 THEN 'No' ELSE 'Yes' END It simply states that when value of column period is <=20 then 'No' will be populated for column A and for rest of the values 'Yes' will be populated for column A
column B: PREIOD >20 THEN ‘Yes’ ELSE ‘No’ ENDIt simply states that when value of column period is >20 then 'Yes' will be populated in column B and for rest of the values 'No' will be populated for column B
For further help see the help file.Go to functions Answres and see the case when decription.
Regards,
Sandeep
Edited by: Sandeep Saini on 25-Nov-2010 00:46
Similar Messages
-
Doubt in case statement in sql
hiii guruz
i am writing a code in HR schema for case its like this it works fine as i want it to
select commission_pct ,
case
when commission_pct is null
then 'null'
else 'not null' end "comm"
from employees
but when i write+
select commission_pct ,
case commission_pct
when null then 'null'
else 'its not null'
end "chk"
from employees
the o/p that i get is only in every field
its not null
why is it not showing
*'null'*
as it was supposed to show it
thksoracle 10g
using sql *plus -
Hi,
I need some help with a simple case statement. lets say i have a table called name which has following 2 rows -
ID first_name last_name
1 JOHN SMITH
2 JOHN
i want to write a statement like :-
select id,case when first_name like '%JO%' then 'John in first_name'
when last_name like '%SM%' then 'Smith in last_name'
end result from sample_table;
The result displayed is -
1 John in first_name
2 John in first_name
how can i rewrite this query to also include a 3rd row which will display the result as -
1 John in first_name
2 John in first_name
1 Smith in last_name
I want to display this 3rd row which displays last name also.
Please help.974647 wrote:
Hi,
I need some help with a simple case statement. lets say i have a table called name which has following 2 rows -
ID first_name last_name
1 JOHN SMITH
2 JOHN
i want to write a statement like :-
select id,case when first_name like '%JO%' then 'John in first_name'
when last_name like '%SM%' then 'Smith in last_name'
end result from sample_table;
The result displayed is -
1 John in first_name
2 John in first_name
how can i rewrite this query to also include a 3rd row which will display the result as -
1 John in first_name
2 John in first_name
1 Smith in last_name
I want to display this 3rd row which displays last name also.
Please help.Hi,
welcome to the forum.
Please read SQL and PL/SQL FAQ
Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
What you want to achieve cannot be done with a single query without using some tricks.
Let's start from the point that your table has 2 rows. If you make a query without using a filter (A WHERE clause) and without using any CONNECT BY clause the number of rows returned by your query will be 2.
So a possible solution is to make a union of the same table applying the condition to select only records that you want to display.
i.e.:
First I select only records having first_name like '%JO%' then I make a union with all rows having last_name like '%SM%'WITH sample_table AS
SELECT 1 id, 'JOHN' first_name, 'SMITH' last_name FROM DUAL UNION ALL
SELECT 2 id, 'JOHN' first_name, NULL last_name FROM DUAL
SELECT id, 'John in first_name' txt
FROM sample_table
WHERE first_name like '%JO%'
UNION ALL
SELECT id, 'Smith in last_name' txt
FROM sample_table
WHERE last_name like '%SM%';
ID TXT
1 John in first_name
2 John in first_name
1 Smith in last_name
Regards.
Al
Edited by: Alberto Faenza on Dec 3, 2012 5:27 PM
Removed case, no need -
How to create nested CASE statements in PL/SQL
Can anyone please tell how to create Nested CASE statements in PL/SQL with proper syntax?
It would be better if you can help with an example.
Thank you!Something like this:
SQL> set serveroutput on
SQL> declare
2 v1 number := 2;
3 v2 varchar2(1) := 'C';
4 begin
5 case v1
6 when 1 then dbms_output.put_line('First');
7 when 2 then begin
8 case v2
9 when 'A' then dbms_output.put_line('Found A');
10 when 'B' then dbms_output.put_line('Found B');
11 when 'C' then dbms_output.put_line('Found C');
12 else dbms_output.put_line('NONE');
13 end case;
14 end;
15 else dbms_output.put_line('Else');
16 end case;
17 end;
18 /
Found C
PL/SQL procedure successfully completed
SQL> If you have further doubts regarding syntax you can read the docs on the Case statement here:
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/case_statement.htm -
SQL Expression in decode function or case statement?
Can I put SQL expressions in decode function or case statement?
For example,
select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
from element le;
or
select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
ELSE 'Y'
from element le;
None of the above work.
Can anyone tell me how to make it work?
Is there any workaround?
Thanks,
JYou simply needed and END to your CASE statement;
SQL> with profile_data as (
select 'XXXX_AFTER' name, 1 object_id from dual),
element as (
select 1 profile from dual union all
select 2 from dual)
select le.profile,
case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
THEN 'N'
ELSE 'Y'
END new_col
from element le
PROFILE N
1 Y
2 N -
CASE not found while executing CASE statement on Submit Form
Hi to all APEX users and developers.
I have several APEX applications and they are all working well, but recently I got one strange exception when I try to submit page:
Session: Fetch session header information
...metadata, fetch page info
...Validate item page affinity.
...Validate hidden_protected items.
Add error onto error stack
...Error data:
......message: Error processing request.
......additional_info: ORA-06592: CASE not found while executing CASE statement
......display_location: ON_ERROR_PAGE
......is_internal_error: true
......apex_error_code: APEX.UNHANDLED_ERROR
......ora_sqlcode: -6592
......ora_sqlerrm: ORA-06592: CASE not found while executing CASE statement
.....error_backtrace: ORA-06512: at "APEX_040100.WWV_FLOW", line 9273
......component.type: APEX_APPLICATION_AUTH
......component.id: 41350431648668800
......component.name: MNRFR
...Show Error on Error Page
......Performing rollback
Processes - point: AFTER_ERROR_HEADER
Processes - point: BEFORE_ERROR_FOOTER
End Page Processinga
Page has more than 120 items (most of them are hidden), so my first thought is that page has problem with posting so many items, but APEX error message doesn't hel me at all. Any help would be very appreciated :)
AlmirHi Almir,
actually it is the 100 page item limit. See (http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/limits.htm)
I also had a look into the source code and the code at the position where the error gets raised only supports 100 page items.
Can you have a look into the generated HTML code and look if you have a page items which is mapped to p_t101 or a higher number ?
I will file a bug to show a better error message.
Regards
Patrick
My Blog: http://www.inside-oracle-apex.com
APEX Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolf -
hi.
i have a case statement query. i wonder if in the select statement, can i do computation using different parameter from the main report to subreport?
for example, (qty * parameter)
if parameter = 0, i uses $P{abc} to multiply qty
if parameter > 0, i uses $P{xyz} to multiply qty
in this case, i've writen a sql (as below) but its does not execute.
select ....., (QTY *
case $P{QTY}
when 0 then ' * $P{abc}'
else ' $P{xyz}'
end
from....
hence, what should i do in order to get the right parameter to multiply with? pls guide. thanks.I'm not sure about these parameter placeholders which are specific to whatever report tool you are using, but the structure would be (assuming the parameter value would never be less than zero):
qty * case when $P{QTY} = 0 then $P{abc} else $P{xyz} end -
Case Statement in Answers Filter
Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
Thxziekc wrote:
Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
ThxAccording to your requirements, when the month is January, you want all 12 months; any other number and you want months from 1 to "1 less than the current month number." Yes? Okay, here's what to do:
In the filter on your date column, click on the filter button, convert it to SQL and enter this:
MONTH(tablename.date_column) BETWEEN 1 AND CASE WHEN MONTH(CURRENT_DATE) = 1 THEN 12 ELSE MONTH(CURRENT_DATE)-1 END
Here's the logic:
a) When the current month is January, then the case statement will yield 12 and the filter will be:
WHERE MONTH(tablename.date_column) BETWEEN 1 AND 12 ...or all 12 months.
b) When the current month is any other month, say June, then the case statement will yield one less than the what the month number is, or in this case 5.
WHERE MONTH(tablename.date_column BETWEEN 1 AND 5 ...or all the months from 1 to 5 (Jan through May)
This will give you what you want... -
CASE statement in Calculated column
Hi Frzz,
I have below requirement in Calculated column with CASE statement. Could some one help me how to achieve this with case statement.
String = 0Hello
01Hello
012Hello
0123Hello
If 1st Character of the string is '0' then - 0Hello
1st 2 characters of the String is '01' - 22Hello
1st 3 characters of the String is '01' - 333Hello
1st 4 characters of the String is '01' - 4444Hello
Thank you.
Best Regards,
Krishna.Hi Krishna ,
Using IF and MATCH to do that: ( I took one of the conditions you specified )
IF(match("STRING1",'??0??'),'333Hello',"STRING1")
Output:
Regards,
Krishna Tangudu -
Hi PL/SQL experts,
I'm going a bit loopy here, so could someone please point out what I'm doing wrong with this case statement:
Test procedure is:
CREATE OR REPLACE procedure SCOTT.postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE input_post_code
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A')
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
However, I'm getting the following error:
LINE/COL ERROR
37/6 PLS-00103: Encountered the symbol "WHEN" when expecting one of
the following:
:= . ( % ;
On a second note, can I not have the ELSE structure embedded within the case (currently commented out)?
Thanks very much in advance.
DevFixed code:
CREATE OR REPLACE procedure postcode_validate_2 (input_post_code VARCHAR2) as
alphabet_string VARCHAR2(52) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxwyz';
number_string VARCHAR2(10) := '012345789';
last_part_postcode VARCHAR2(3) := NULL;
BEGIN
IF INSTR(input_post_code,' ') = 0
THEN
DBMS_OUTPUT.PUT_LINE('We need a space in the postcode please');
GOTO exit;
ELSIF LENGTH(SUBSTR(input_post_code,instr(input_post_code,' ')+1)) > 3
THEN
DBMS_OUTPUT.PUT_LINE('Last part of postcode can only be 3 characters');
GOTO exit;
ELSE
last_part_postcode := SUBSTR(input_post_code,instr(input_post_code,' ')+1);
END IF;
CASE
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 2
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 3
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(number_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format A9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format A9A');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(number_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA99');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA99');
-- GOTO exit;
-- END IF;
WHEN (length(substr(input_post_code,1,instr(input_post_code,' ')-1)) = 4
AND instr(alphabet_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(number_string,substr(input_post_code,3,1)) != 0
AND instr(alphabet_string,substr(input_post_code,4,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('We have a valid postcode in the format AA9A');
-- ELSE
-- DBMS_OUTPUT.PUT_LINE('Sorry but that is an incorrect postcode! Format AA9A');
-- GOTO exit;
-- END IF;
END CASE;
-- Check last part of format, should be AA9
IF (instr(number_string,substr(input_post_code,1,1)) != 0
AND instr(alphabet_string,substr(input_post_code,2,1)) != 0
AND instr(alphabet_string,substr(input_post_code,3,1)) != 0)
THEN
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the correct format, 9AA');
ELSE
DBMS_OUTPUT.PUT_LINE('End part of the postcode is in the wrong format!');
END IF;
<<exit>>
DBMS_OUTPUT.PUT_LINE('Please try again');
END;
/As VG2 pointed out you were missing some semicolons.
Also, CASE input_post_code was replaced with just CASE since you are doing a searched case.
Also, END at the end of the case statement was replaced with END CASE. -
Case statement in advanced sql
how to use case statement in advanced sql.Example if quarter=1 i need to select jan,fev,and march months from table
this is the case statement i am using :
case when 1=@{quarter} then substring(cast((etxnmis.month_year) as char) from 5 for 2) IN ('03', '04', '05') else null end
and i get the below error
: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 27002] Near <IN>: Syntax error [nQSError: 26012] . (HY000) -
T-sql case statement in a select
When I execute the following t-sql 2012 statement, the "NO Prod' value is not
being displayed from the sql listed below:
SELECT DISTINCT
IsNull(cs.TYPE,'') as type,
CASE IsNull(Course.TYPE,'')
WHEN 'AP' then 'AP Prod'
WHEN 'IB' then 'IB Prod'
WHEN 'HR' then 'HR Prod'
WHEN '' then 'NO Prod'
END AS label
FROM CustSection cs
INNER JOIN dbo.Person p on P.personID = cs.personID
Left join customCustomer cs564 on cs564.personID = p.personID and
cs564.attributeID ='564'
where ( cs.type is null and cs564.attributeID = null)
or
(cs.type IN ('HR','AP') OR
(cs.type='IB' AND SUBSTRING(cs.code,1,1)='3'))
ORDER BY label
What I want is for 'NO Prod' to be displayed when
cs.type is null and cs564.attributeId is null.
Thus can you tell me how to fix query above so the 'NO Prod' value is displayed in the
select statement listed above?There is no CASE statement in SQL; we have a CASE expression. We do not use the old 1970's Sybase*- ISNULL(); we have COALESCE().
There is no such thing as a magic generic “type” in RDBMS. There is no such thing as a generic “code” in RDBMS. They have to to be “<something in particular>_type” and “<something in particular>_code” in a valid data model. How about blood_type
and postal_code??
There is no such thing as a generic “person” table in RDBMS. First of all, do you really have only one person, as you said?? But the important point is that these persons play a role in the data model – customers, students, etc. You are doing the wrong thing
and doing it badly. This table should not exist any more than a table of “Things” such exist.
And the reason you are beyond any real help is “attribute_id” which tell us that your schema is a total disaster of data and meta data mixed together in a non-RDBMS written in awful SQL. Based on cleaning up bad SQL for 30 years, it looks like you are an OO
programmer who never unlearned his prior mindset.
Why did you allow an encoding schema with blanks? Why do you have so many NULL-able columns?
SELECT DISTINCT is very rare in a properly designed schema. The DRI references assure that rows cam be matched. To get you started, look at this skeleton:
CREATE TABLE Products
(product_gtin CHAR(15) NOT NULL PRIMARY KEY,
product_type CHAR(2) DEFAULT 'XX' NOT NULL
CHECK (product_type IN ('AP', 'IB', 'HR', 'XX'))
The table name is a plural noun because it models a set (NOT an OO class).
The GTIN is an industry standard identifiers, and not have to invent our own.
The product_type (not blood_type, not automobile_body_type!) has a constraint that assures it is never NULL and never blank; I invented 'XX' as a default.
You need more help than you can get in a forum, but if you will follow Netiquette and post the DDL, we can get you started.
--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 want to do something like this in a SELECT where I set the value of one field based on another. Is this possible. If not are there any alternatives? Thanks
CASE WHEN [var_cpnt_brkpt_ct] = '0' THEN [enrc_cpnt_var_price_rt] = '0'There is no CASE statement in SQL; we are a declarative language. We have a case expression! There is no control flow, like you are trying to write. You do not even know that fields are columns. This is as silly
as asking for the color the feathers on a fish.
--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
Thank you for your support. Good day Sir. -
CASE Statement in Where Condition with Multi Valued parameter in SSRS
Hi All,
I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
SELECT
Logic here
WHERE
Date IN (@Date)AND
(CASE
WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
WHEN ABC_ID IS NULL THEN 'GROUP3'
ELSE 'GROUP4'
END ) IN (@GROUP)
So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
For @Date one dataset will pass the available and default values and
for @GROUP parameters, another dataset will pass the available and default values.
But this is not working as expected. Please suggest me where I am making mistake in the query.
Maruthu | http://sharepoint-works.blogspot.comHi Maruthu,
According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Hi,
I have query with a case statement as follows:
SELECT * FROM table
WHERE
CASE WHEN :variable like 'A' THEN column END is null
WHEN :variable like 'B' THEN column END is not null;
This works fine when returning "column is null" but not when "column is not null".
Can I use a CASE statement like this?
Thanks
LucyMy data is too complicated to show, but depending on the value of the bind variable in the statement I want to return all the rows in a query where the data in a particular column is either null or not null.For example, looking at the EMP table, if my bind variable is whether I want to show the top manager or not, if set to 'Yes' I would like to return all rows of the EMP table where mgr is null (i.e. the one row where ename is 'KING'), if it were set to 'No' I would like to return all the rows where mgr is not null (i.e. all the other rows). The difference with my query is that the column contains strings, not numerics.
I've used a CASE statement before where I equate the column to a particular value and that works fine, but I'm not sure how they deal with nulls. I've also tried DECODE and didn't get anywhere with that.
Thanks
Lucy
Maybe you are looking for
-
I AM USING WINDOWS XP. WHEN I AM CONNECTING MY IPOD TOUCH MODEL NO. MC 008LL TO MY PC ,CHARGING INDICATION IS COMING BUT NEITHER THE WINDOWS NOR THE LATEST VERSION I TUNE 10.6.3 DETECTING MY IPOD. IT IS ALSO NOT SHOWING IN I TUNE WINDOWS."DEVICE LIS
-
Installed the latest update and now Finder refuses to start/crashes
Hey guys, I just installed the latest 10.4.11 update or whatever, along with Quicktime, iTunes, etc., and now when I log in to any account, Finder refuses to start. If it does start, it crashes. I've googled around and all I could find was that I sho
-
Has anyone installed Leopard on a (2004) 1st Gen G5 1.8 Processor with 768 MB of ram? If so, any problems? Thanks.
-
Broadcast message does not appear
Hi, I have finished all configuration settings and I sent the message successfully and check in sent log and every thing is ok.. but no message appeared in agents screen at the bottom as usual. your help will be highly appreciated. Regards, Yasser
-
X/Motif Solaris 6 to Solaris 10
motif patch concerns on solaris 6 to 10. Edited by: gsatish on Feb 19, 2009 1:15 AM