Use of Case in Select statement
Hi All,
Can anyone tell me whats wrong im doing in the following select statement. I am selecting most this fields from Global Temperory Table and few from normal DB tables.
select h.Taskid,h.Flowid,fd.DESCRIPTION Flowname,h.Stepid, sd.DESCRIPTION Stepname,h.Lockby,ud.USERNAME,h.Status,case Date_initiated when (Currval.Testid = Nextval.Testid) Then Date_initiated := NULL Else Date_initiated := Date_initiated End case,case UserTime When ((Currval-1).Testid IS NULL or Currval.Testid <> (Currval-1).Testid) Then UserTime := StartTime When (Currval.Testid = (Currval-1).Testid or Currval.Testid <> Nextval.Testid or Nextval.Testid IS NULL) Then UserTime = (Currval-1).Endtime End case,case StartTime When(Currval.Stepid = Nextval.Stepid or Currval.Stepid=9999) Then StartTime := NULL Else StartTime := StartTime End case,h.EndTime,h.LockTime,h.Drawer,h.FileNo,h.DocType from GlobalTempTest h inner join USERDEFINITION ud on h.Lockby=ud.USERID inner join FLOWDEFINITION fd on h.Flowid=fd.FLOWID inner join STEPDEFINITION sd on (h.Stepid=sd.STEPID and h.Flowid=sd.FLOWID)
Hope so get some response soon.
Thanks in Advance
You have to rewrite your code like this:
CASE WHEN (Currval.Testid = Nextval.Testid) THEN NULL
ELSE Date_initiated
END New_Date_initiatedCurrval/Nextval as shown in your example will not work. Please explain what you mean by previous value comparison.
C.
Similar Messages
-
Case in Select Statement - Ramya
Hi All,
Could any body help me out ,how to use the CASE in select Statement
Thanks in Advancehere is an example:
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7566 JONES MANAGER 7839 02-APR-81 2975 1000 20
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 12-JAN-83 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7934 MILLER CLERK 7782 23-JAN-82 1300 10
14 rows selected.
SQL> select empno,
2 ename,
3 job,
4 case when job = 'PRESIDENT' then 1
5 when job = 'MANAGER' then 2
6 when job = 'SUPERVISOR' then 3
7 else 4
8 end rank
9 from emp;
EMPNO ENAME JOB RANK
7566 JONES MANAGER 2
7902 FORD ANALYST 4
7839 KING PRESIDENT 1
7698 BLAKE MANAGER 2
7782 CLARK MANAGER 2
7369 SMITH CLERK 4
7499 ALLEN SALESMAN 4
7521 WARD SALESMAN 4
7654 MARTIN SALESMAN 4
7788 SCOTT ANALYST 4
7844 TURNER SALESMAN 4
7876 ADAMS CLERK 4
7900 JAMES CLERK 4
7934 MILLER CLERK 4
14 rows selected.
SQL> -
How to use SET ID in select statement of SQ02
Hi,
I have a infoset, where for one of my Zfield, i have writen a select statement in order to get my ouput.
if aufk-aufnr = 'XYZ'.
select sum( FKBTR ) from fmifiit into zfmifiit
where fikrs = aufk-kokrs
and fipex IN capex
and wrttp NE '51'.
endif.
For the above statement, i have created (with 10 single values, table name FMCI, field name FIPEX) a SET id named CAPEX and used with IN operator.
But when i generating the infoset i am getting error like below
The IN operator with "CAPEX" is followed neither by an internal table nor by a value list
I was using IN opeartor for set ids during validation / substitutions, where if i have to validate multiple single values.
What to do here?
Regards,
Srinu[OPEN-SQL|http://help.sap.com/abapdocu_70/en/ABENOPEN_SQL_GENERAL.htm] set of statement, [SELECT|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] statement, [WHERE|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP.htm] addition requires a selection table (type range, [WHERE - IN seltab |http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SELTAB.htm]) of parameter and not a set. We are in Abap here, not in a Customizing screen
You have to convert the set to a selection table in an ABAP coding before using it in a SELECT statement.
(Check FM like G_SET_TREE_IMPORT to import definition of set (values and intervals) and map them to a select-table, or ask a developper to perform it, look at G_SET_TREE_IMPORT -> select statement)
Regards,
Raymond -
Using plsql tables in select statement of report query
Hi
Anyone have experience to use plsql table to select statement to create a report. In otherwords, How to run report using flat file (xx.txt) information like 10 records in flat files and use this 10 records to the report and run pdf files.
thanks in advance
sureshhi,
u can use the utl_file package to do that using a ref cursor query in the data model and u can have this code to read data from a flat file
declare
ur_file utl_file.file_type;
my_result varchar2(250);
begin
ur_file := UTL_FILE.FOPEN ('&directory', '&filename', 'r') ;
utl_file.get_line(ur_file, my_result);
dbms_output.put_line(my_result);
utl_file.fclose(ur_file);
end;
make sure u have an entry in ur init.ora saying that your
utl_file_dir = '\your directory where ur files reside'
cheers!
[email protected] -
Error by using database procedure in select statement
hi ,
I have built a database procedure having one parameter with in out varchar type. that return value with some addition.
i am using it with some column in select statement only for display purpuses but i am facing error by doing that in select statement. that procedure is working well with bind variable but not with select statement.
plz help me how i can use a procedure in select statement. or can i do it or not.plz help me how i can use a procedure in select statement. or can i do it or not.A workaround could be to create a wrapper function for your procedure. One that only passes the input parameters and returns the output parameter.
The simply call this function in your select which internally calls the procedure. -
Using java function in select statement
Hi,
I am trying to use java function in select statement.
public class ClassA{
private static String MyConst = "foo";
public static String functionA(){
return MyConst;
in my query I have:
select
ClassA.functionA() AS id,
groupId AS newID,
from
myChannel[now]
ClassA is part of the application (no need to import).
I get and error of Invalid Expression on ClassA.functionA().
I also tried to declare the function in the processor element:
<wlevs:processor id="proc">
<wlevs:function function-name="A" exec-methode="functionA">
<bean class="mtPackage.ClassA"/>
</wlevs:function>
<wlevs:processor>
but then I get a different error in the processor XML file: "An InvocationTargetException was encoutered while attemting to register the user defind function A. The message was null"
What am I missing here?Hi,
From the above description, you have tried two manners to call method functionA() in the user defined class ClassA. One uses java cartridge manner directly and the other try to use user defined function manner.
For the java cartridge manner, the following CQL query should work if the ClassA is really included in the OEP app. I have done similar test before, it works.
select
ClassA.functionA() AS id,
groupId AS newID,
from
myChannel[now]
For user defined function manner, I think two things you need to change:
1. Need to declare the function in the EPN assembly file(under META-INF/spring/), not component configuration file(under META-INF/wlevs/). The following is an example:
<wlevs:processor id="proc">
<wlevs:function function-name="A" exec-methode="functionA">
<bean class="mtPackage.ClassA"/>
</wlevs:function>
</wlevs:processor>
2. Call the user defined function in the CQL query in the component configuration file under processor. For example:
select A() from myChannel
Regards,
XiYing -
Hello,
in Oracle8 I've the following problem:
The statement
SELECT ''' | ''||' || 'rpad'
|| '(''' || column_name
|| ''',' ||
(CASE WHEN (data_type = 'VARCHAR2' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'CHAR' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'CLOB' AND
data_length > 50) THEN
to_number('50')
WHEN (data_type = 'DATE' AND
data_length != 19) THEN
to_number('19')
ELSE
data_length
END )
|| ', '' '')||' AS column_name
FROM dba_tab_columns
WHERE
table_name = upper('DBA_TABLES') AND
owner = upper('SYS')
ORDER BY column_id;
works fine but defining the same statement as a cursor in a PL/SQL Procedure, I got a
Error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
( - + mod not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string>
The same procedure can be compiled in Oracle9i without errors.
Does anybody know if there are any restrictions using CASE statements in a PL/SQL CURSOR in Oracle8?
Thanks
PatricHi,
I am encountering the same problem.
Can u suggest the decode statement used instead of case
for this select clause which uses the CASE statement ?
SELECT
CASE
WHEN S.cmpy_num = S.cpty_borg_num THEN
''OURS''
ELSE
''THEIRS''
END AS SDIOwner,
From TABLE -
Using Multiple Parameters in Select Statement
My goal is to be able to use more than one parameter for the select statement. When I use OR instead of AND it works but with only one parameter. I thought using AND would return any parameter that is listed in the ?Report Based On}. Any ideas why this will not work?
I've created four parameters:
Report Based on (string) Allow Multiple Values (Default Values: Customer, Part Id, and Serial Number)
RMA info by Customer (string)
RMA Info by Part Id (string)
RMA Info by SN (string)
This is my select statement
(if {?Report Based On} = "Customer" then
{RMA_Information.Customer}LIKE{?RMA info by Customer})
and
(if {?Report Based On} = "Part Id" then
{RMA_Information.Part Id}LIKE{?RMA Info by Part Id})
and
(if {?Report Based On} = "Serial Number" then
{RMA_Information.Serial Number}={?RMA Info by SN })
tx ShirleyTry this...
IF "Customer" IN {?Report Based On} AND
"Part Id" IN {?Report Based On} AND
"Serial Number" IN {?Report Based On}
THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
{RMA_Information.Part Id}LIKE{?RMA Info by Part Id} AND
{RMA_Information.Serial Number}={?RMA Info by SN}
ELSE
IF "Customer" IN {?Report Based On} AND
"Part Id" IN {?Report Based On}
THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
{RMA_Information.Part Id}LIKE{?RMA Info by Part Id}
ELSE
IF "Customer" IN {?Report Based On} AND
"Serial Number" IN {?Report Based On}
THEN {RMA_Information.Customer}LIKE{?RMA info by Customer} AND
{RMA_Information.Serial Number}={?RMA Info by SN}
ELSE
IF "Part Id" IN {?Report Based On} AND
"Serial Number" IN {?Report Based On}
THEN {RMA_Information.Part Id}LIKE{?RMA Info by Part Id} AND
{RMA_Information.Serial Number}={?RMA Info by SN}
ELSE
IF "Customer" IN {?Report Based On}
THEN {RMA_Information.Customer}LIKE{?RMA info by Customer}
ELSE
IF "Part Id" IN {?Report Based On}
THEN {RMA_Information.Part Id}LIKE{?RMA Info by Part Id}
ELSE
"Serial Number" IN {?Report Based On}
THEN {RMA_Information.Serial Number}={?RMA Info by SN}
HTH,
Jason -
How to use 'is null' in select statement of ABAP program
hi,
I want to use 'is nul' or 'not null' in select statement of my ABAP program for any field. I have written below query but I am getting sy-subrc = 4 and getting no data.
SELECT * FROM mara INTO TABLE it_mara
WHERE volum IS NULL .
Can anyone resolve this.Hi PKB,
Check the below thread for NULL and Space value in ABAP . It will help you
NULL and Space value in ABAP
Regards,
Pawan -
Use of wildcard * in SELECT statement
I have read that the use of the wildcard * in a SELECT statement cannot be utilized when using the INSERT INTO or other queries where data column/field alignment is critical. I have noted that the INSERT INTO column/fields must be in the same order
as the SELECT statement (as there is no alignment to column/field names). Can someone please provide me with the information or article that covered this scenario?It is consider a good practice to specify columns name, however , SQL Server is smart enough to insert the data without too , but only if the table does not have an IDENTITY property
CREATE TABLE #t (c1 int, c2 char(1),c3 real, c4 bit)
CREATE TABLE #t1 (c1 int, c2 char(1),c3 real, c4 bit)
---Same thing with INSERT like SELECT * you asked
INSERT INTO #t1 VALUES (1,'A',2.5,0)
INSERT INTO #t1 VALUES (2,'B',3.5,1)
INSERT INTO #t1 VALUES (3,'C',4.5,0)
INSERT INTO #t SELECT * FROM #t1
SELECT * FROM #t
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Using Variables in a select statement through a Database Adapter
I was wondering how I reference a variable in a select statement through a Database Adapter.
Ex.
1. I have a global variable that stores an employee number
2. I want to select an SSN # from a table based on an employee #
variable.
select ssn from emp where ssn = :input_variable - ????
- how do i reference the variable - I am getting a 'missing IN or OUT parameter error?
Any advice is much appreciated.
~ThanksI'm just wondering if anyone knows a work around so that I might be able to store a Table's FIELD name in a variable or an array[] so that I can do a query based on the decision of a loop without having to code 10 IF/ELSE statements.For instance, although the above code will not work, this code, although quite lengthy, does:
If DataGrid1.SelStartCol = 0 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES__PUR_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 1 Then
Adodc1.RecordSource = "Select * from tblReservation order by VENDOR"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 2 Then
Adodc1.RecordSource = "Select * from tblReservation order by VEN_LOC"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 3 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_TYPE"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 4 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_FROM_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 5 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_TO_DT"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 6 Then
Adodc1.RecordSource = "Select * from tblReservation order by MISC_ADJ"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 7 Then
Adodc1.RecordSource = "Select * from tblReservation order by STATE_TAX"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 8 Then
Adodc1.RecordSource = "Select * from tblReservation order by LOC_CHARGE"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 9 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_ID"
Adodc1.Refresh
ElseIf DataGrid1.SelStartCol = 10 Then
Adodc1.RecordSource = "Select * from tblReservation order by RES_OP"
Adodc1.Refresh
End If
Do you see where i'm going with this?
I simple want to use a variable in the "select * from <Table> Order by <Field>" -
Using TRIM function in select statement
Hi All,
I'm using the TRIM function in my select statement to eliminate the white spaces.
But while using in select the TRIM function is not working in SQL*PLUS client(The query returns the white spaces also)
Kindly provide some pointers regarding the issue.........
I want to get only the data without the spaces in select statement
Regards,
MohanHi, Mohan,
SQL*Plus always pads columns to make them line up nicely.
If you have a column declared as VARCHAR2 (20), then SQL*Plus will normally display 20 characters for that column, even in the maximum actual length is, say, 5 (or even if the column always happens to be NULL).
If you want the output to include only the actual data, without the padding that SQL*Plus adds, then concatenate all the columns into one big string column.
People often do something like the following to generate a CSV file, with no exta spaces:
SELECT TO_CHAR (empno)
|| ',' || ename
|| ',' || job
|| ',' || TO_CHAR (deptno)
|| ',' || TO_CHAR (hiredate, 'DD-Mon-YYYY') AS all_data
FROM scott.emp; -
Using variables in the Select statement
Here is my Select statement:
Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, JeremyHere is my Select statement:
Set EmpDynaset = OraDatabase.CreateDynaset("select CU_NAME,CU_CONTACT from CU where CU_Name =" & cnt, 0&)
What's wrong with this? I'm trying to use the variable cnt. Any help? Thanks, Jeremy Perhaps using the following:
("select CU_NAME,CU_CONTACT from CU where CU_Name = :variable")
then binding the variable to a value before executing the statement.. -
Delete adjacent duplicates how to use in the below select statement
hi i have a problem
i am suing the below select statement
SELECT a~extno
a~guid_lclic " for next select
e~ctsim
e~ctsex
*revised spec 3rd
f~guid_pobj
f~amnt_flt
f~amcur
f~guid_mobj
e~srvll "pk
e~ctsty "PK
e~lgreg "PK
INTO TABLE gt_sagmeld
FROM /SAPSLL/LCLIC as a
INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic " for ccngn1 selection
inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
where a~extno in s_extno.
sort gt_sagmeld by guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ.
delete adjacent duplicates from gt_sagmeld comparing guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ .
now i am confused how to use delete adjacent dupliacate and on which fields
as first table /sal../lclic primary key is guid_lclic
and it is joined to table
legcon by guid_lclci ( not a primary key here)
legcon primary key is guid_legcon
and table 3 legsv by lgreg (pk here)
table 3 has tow more primary key srvll and ctsty also
NOW MY QUESTIO IS TAHT IS I USE ABOVE DELETE ADJACENT STATMENT IT FETCHES 20 LAKH RECORDS
I WANT TO REDUCE IS LET ME KNOW ON WHAT fields i need to use delete adjacen duplicates
or use comparing all fields?
regards
Arorahi sudha
if u see my select statement is contains four Primary keys
srvll
lgreg
ctsty
guid_lclic
but the next table connected to this table legcon is by guid_pobj and anothe table by guid_mobj
and if i take this gt_sagmeld to another temp table and i find abt 10 lakh uniques guid_pobj
similary 6 lakh guid_mobj so the next slect is hanpering because of this
not COMING TO OUR POINT IF I SORT ONLY BY OUR PRIMARY KEYS NOT TAKING INTO ACCOUNT TEH GUID_POBJ AND GUID_MOBJ
THE ENTRIES ARE VERY LESS BUT IF I TAKE INOT ACCCOUNT IN GT_SAGMELD THE ENTRIES ARE ABT 20 LAKH
SO I AM NOT SURE WHETHER TO TAKNE GUID_POBJ AND GUID_MOBJ INOT ACCOUNT FOR DELECTING ADJACENT DUPLICATES?
HENCE THE QUESTION OF ON WHICH FIRLD DELETE OR COMPARING ALL FIELDS I USE? -
Problem - Creating a Dynamic LOV using duplicate value in select statement
I am trying to create a Dynamic LOV by attempting to follow a pattern similar to the following:
select shop_name d, shop_id r
from shops
order by 1
However, I want to use the shop_name twice as in the following because I do not have any other unique identifier available such as a shop_id to associate with the shop name:
select shop_name d, shop_name r
from shops
order by 1
But I get an error where I am not allowed to duplicate the shop_name in the select statement. I read somewhere on this forum where it can be done but I can't find exactly how.
Can someone tell or show me how to accomplish this?
Thanks in anticipation for your answer.
Thanks,
RicRic,
I just tried to do this on APEX 3.0, and it worked just fine with this SQL:
select ename d, ename r from emp order by 1Perhaps you could put an example on apex.oracle.com or specify the error message that you're getting.
So as long as you have uniquely aliased both columns, this should not present a problem.
Thanks,
- Scott -
Maybe you are looking for
-
How do I erase all aps from ipad 1 and put them on ipad2?
My ipad2 has shipped. I want to give my ipad1 to a colleagues=, but I want to give it to him without my stuff (music, email addresses, aps, photos, etc.) as if it is all new. I also do not want my itunes to assume that the ipad1 is still a device I a
-
Problem On Editing a Smartform in PDF with Chinese
Hello, we are using SRM and in a specific transaction we are generating a SAP message wich is editing a form for the PO. When we want to edit it on SRM in chinese we have problem with a lot of ### ans everything wich doesn't mean anything. To gener
-
Descriptions of individual episodes of my podcast NOT showing up in iTunes Store Listing
Podcast feed: http://talkradiomeltdown.com/podcast.xml Feedburner variant feed: http://feeds.feedburner.com/talkradiomeltdown Store listing: http://talkradiomeltdown.com/itunes I have coded my podcast feed entirely by myself, using the template provi
-
"Desktop" shows up 4 times in File-- Open sidebar
Hi, Within the last week or so I have noticed that "Desktop" shows up 4 times in the places sidebar when I go to File --> Open from any program. In finder itself I don't have "Desktop" in the places sidebar at all. I thought Spaces could be the culpr
-
Cannot load restored bootcamp parition
I have upgraded my HD and in the process also upgraded my OSX to Yosemite. I have now restored my bootcamp partition from my old HD, but can't get it to load. When rebooting and holding down the alt key it does not show, nor can I get it to boot in P