Need a select statement to trim a single value out of a column
I have a column which can and does contain single and multiple values. For instance, there could be a single value, value, or it could look like this value, value, with there being a comma and a space between the two values. I need a select statement that will only and always return the value to the left or in the case of a single value with no comma, just that value. TIA
If your single value has no comma, just the value, then you need an extra DECODE to resolve that case.
SELECT DECODE(INSTR(text,','),0,text,SUBSTR(text,1,INSTR(text,',')-1))
FROM (SELECT 'value1' text
FROM dual
UNION
SELECT 'value2, value3'
TEXT from dual)TTFN
John
Similar Messages
-
Select statement for retrieving infotype 1005 values w,r,t payscale
Hi All,
could you pls help me for the below requirement
"select statement for retrieving infotype 1005 values with respect to the pay scale level.
because pay scale level is having range of values in the infotype"
Thanks in advance
Prasad
Please try it yourself first.
Edited by: Suresh Datti on Aug 9, 2009 4:52 PMHi,
Code which you have written is correct when the R_DATE is having LOW and HIGH values, if the R_DATE is having only LOW value then this will be wrong, becuse if the R_DATE is having only LOW then OPTION value is not BT is should be EQ
Regards
Sudheer -
Help need in select statement?
Hi experts...
I have an internal table with 2 records...i_mara with fields matnr and ersda
matnr ersda
2345 01/26/2007
3445 02/05/2007
i need to write a select statement to collect all MBLNR from MKPF table where BUDAT is in between 01/26/2007 and 02/05/2007..
Thanx
GiriHI vasanth and rich...
thanks for replies...
vasanth i am getting error with the statement.. so i assigned 6 points to u..
DATA: RA_BUDAT RANGE OF BUDAT WITH HEADER LINE.
Unable to interpret range.... Possible error with spelling or comma
Rich: ur solution worked good....
is there any possible simplest way... or this is the best way includes performance?
Regards
Giri -
Help needed in select statement
Hi gurus,
I have a table with orderentry and ordertype
case 1 :
i want to get the set of records when ordertype =1 repeats
case2:
i want to get the set of records when there is no ordertype =1
CREATE TABLE test
orderentry NUMBER,
ordertype NUMBER
INSERT into test
values ( 10,1);
INSERT INTO test
VALUES (10, 2);
INSERT INTO test
VALUES (10, 1);
INSERT INTO test
VALUES (10, 2);
INSERT INTO test
VALUES (11, 1);
INSERT INTO test
VALUES (11, 2);
INSERT INTO test
VALUES (11, 2);
INSERT INTO test
VALUES (11, 2);
INSERT INTO test
VALUES (12, 1);
INSERT INTO test
VALUES (12, 1);
INSERT INTO test
VALUES (12, 2);
INSERT INTO test
VALUES (12, 2);
INSERT INTO test
VALUES (13, 2);
INSERT INTO test
VALUES (13, 2);
INSERT INTO test
VALUES (13, 2);
COMMIT;
I want the set of records when the ordertype 1 repeats
my result should be:
case 1:
orderentry ordertype
10 1
10 2
10 1
10 2
12 1
12 1
12 2
12 2
case 2:
orderentry ordertype
13 2
13 2
13 2
Thanks in advanceHello
Thank yuo for posting the create table statements and sample data. I think these do what you are looking for
--case 1
SELECT
orderentry,
ordertype
FROM
SELECT
orderentry,
ordertype,
COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
FROM
t_test
WHERE
ct > 1
--case 2
SELECT
orderentry,
ordertype
FROM
SELECT
orderentry,
ordertype,
COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
FROM
t_test
WHERE
ct = 0
DTYLER_APP@pssdev2> select * from t_test;
ORDERENTRY ORDERTYPE
10 1
10 2
10 1
10 2
11 1
11 2
11 2
11 2
12 1
12 1
12 2
12 2
13 2
13 2
13 2
15 rows selected.
DTYLER_APP@pssdev2> SELECT
2 orderentry,
3 ordertype
4 FROM
5 (
6 SELECT
7 orderentry,
8 ordertype,
9 COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
10 FROM
11 t_test
12 )
13 WHERE
14 ct > 1
15 /
ORDERENTRY ORDERTYPE
10 1
10 2
10 1
10 2
12 1
12 1
12 2
12 2
8 rows selected.
DTYLER_APP@pssdev2> SELECT
2 orderentry,
3 ordertype
4 FROM
5 (
6 SELECT
7 orderentry,
8 ordertype,
9 COUNT(CASE WHEN ordertype=1 THEN 1 END) OVER(PARTITION BY orderentry) ct
10 FROM
11 t_test
12 )
13 WHERE
14 ct = 0
15 /
ORDERENTRY ORDERTYPE
13 2
13 2
13 2
3 rows selected. -
Hi,
I have a table:
table: Acct_Hist
(Acct_id number,
Acct_type_id number,
Acct_ver_id number,
Acct_bal number,
Acct_low_bal number)
I want to retrieve all accounts where there is a change in acct_type_id.
Please help me.It is always helpful when you post here to provide the following:
1. Oracle version (e.g. 10.2.0.4)
2. Sample data in the form of CREATE and INSERT statements. You have provided us the CREATE statement but no data to work with.
3. Expected results.
4. Logic to achieve the expected results.
5. Please use \ tags for #2 and #3.
Edited by: Centinul on Nov 30, 2009 1:16 PM
Removed SQL until further clarification is provided. -
Select-option to restrict to single value
Hi,
I have select-option for company code (i dont want to use parameter) and used no-intervals but it still displays right arrow which will allow users to enter more than one company code. is there any way I can supress this right arrow button.
Regards
KasiSay also NO-EXTENSION.
tables: t001.
select-options: s_bukrs for t001-bukrs no intervals no-extension.
Regards,
Rich Heilman -
Displaying single value (Record) into multiple columns
Hi All,
I want to display the single record into multiple columns. Please let me know How to achieve this..
Record:
Lvl Activity Acre
6 Week 4 (Same value to be displayed into 3 columns.)
REquired output:
lvl Activity PH1 PH2 PH3
6 Week 4 4 4
Thanks
Kaviuser533671 wrote:
Hi,
Thanks for immediate reply.
PH1, PH2, PH3, ... will go more columns based on parameter , what we are passing.An single SQL statement cannot have a dynamic number of columns based on the data itself. The projection (columns returned) have to be known before any data is fetched... and that includes some 'parameter' value.
{thread:id=2309172}
You can build a query dynamically, based on a parameter or even on the data, but 99 times out 100 people use dynamic queries where they are not needed.
Perhaps explain to us what you are really trying to achieve and why, and we could suggest some better way. -
Dynamic sql for select statement
Hi,
Please help me with the below code:
It is updating null if the select statment returns one values. If it fetches multiple values then it throughs the below error msg when running the program.
Please let me know how to modify the below code. Or let me know is there anyother way to write this code.
Logic for development:
* View name should be passed as dynamic.
CREATE OR REPLACE
PROCEDURE "PKEP_LOAD_SO_EU" (p_var1 IN VARCHAR2)
IS
lv_sql VARCHAR2 (4000);
lv_name VARCHAR2 (20);
BEGIN
lv_sql :=
' SELECT DISTINCT LEVEL2
FROM BIIO_SALES_OB_IMPORT_'|| p_var1;
EXECUTE IMMEDIATE lv_sql
INTO lv_name;
BEGIN
UPDATE BIIO_SALES_OB_IMPORT_NA2 --table name for updation
SET SOB_1 = NULL,
SOB_DATE_1 = NULL
WHERE level2 = lv_name; -- validation ( eg. Select distinct level2 from biio_sales_ob_import_'||p_var1)
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLERRM);
NULL;
END;
END;
BEGIN
PKEP_LOAD_SO_EU ('NA1');
end;
Error report:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "DEMANTRA.PKEP_LOAD_SO_EU", line 11
ORA-06512: at line 2
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
Thanks.
PadmaPadu wrote:
Please let me know whether is anyother way to write this code as im a beginner for SQl.You dont need to have a seperate SELECT statement. Just a single UPDATE will do the job for you.
create or replace procedure pkep_load_so_eu
p_var1 in varchar2
as
begin
lSql := ' update biio_sales_ob_import_na2 ' ||
' set sob_1 = null ' ||
' , sob_date_1 = null ' ||
' where level2 in ( ' ||
' select level2 ' ||
' from biio_sales_ob_import_' || p_var1 ||
execute immediate lSql;
end; -
Secondary Index Select Statement Problem
Hi friends.
I have a issue with a select statement using secondary index,
SELECT SINGLE * FROM VEKP WHERE VEGR4 EQ STAGE_DOCK
AND VEGR5 NE SPACE
AND WERKS EQ PLANT
%_HINTS ORACLE
'INDEX("&TABLE&" "VEKP~Z3" "VEKP^Z3" "VEKP_____Z3")'.
given above statement is taking long time for processing.
when i check for the same secondary index in vekp table i couldn't see any DB index name with vekp~z3 or vekp^z3 or vekp____z3.
And the sy-subrc value after select statement is 4. (even though values avaliable in VEKP with given where condition values)
My question is why my select statement is taking long time and sy-subrc is 4?
what happens if a secnodary index given in select statement, which is not avaliable in that DB Table?Hi,
> ONe more question: is it possible to give more than one index name in select statement.
yes you can:
read the documentation:
http://download.oracle.com/docs/cd/A97630_01/server.920/a96533/hintsref.htm#5156
index_hint:
This hint can optionally specify one or more indexes:
- If this hint specifies a single available index, then the optimizer performs
a scan on this index. The optimizer does not consider a full table scan or
a scan on another index on the table.
- If this hint specifies a list of available indexes, then the optimizer
considers the cost of a scan on each index in the list and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes from this list and merge the results, if such an
access path has the lowest cost. The optimizer does not consider a full
table scan or a scan on an index not listed in the hint.
- If this hint specifies no indexes, then the optimizer considers the
cost of a scan on each available index on the table and then performs
the index scan with the lowest cost. The optimizer can also choose to
scan multiple indexes and merge the results, if such an access path
has the lowest cost. The optimizer does not consider a full table scan.
Kind regards,
Hermann -
How do I return the results of two SELECT statements in to one result?
I want to do this without using UNION.
Here's an example of what I'm trying to do:
I have a table called COUNTRY with the following columns:
COUNTRY
COUNTRY_CODE
DATE_VISITED_LAST
POPULATIONI have another table called STATE_COUNTY with the following columns:
STATE_COUNTY
COUNTRY_CODE
STATE_COUNTY_CODE
DATE_LAST_VISITED
POPULATIONI have a third table called TOWN with the following columns:
TOWN
COUNTRY_CODE
STATE_COUNTY_CODE
TOWN_CODE
DATE_LAST_VISITED
POPULATIONNow through the interface I have, a user will supply a country code. I need a SELECT statement that will return a table with the following result set:
The COUNTRY_CODE entered including the DATE_LAST_VISITED and POPULATION for this country
------> All the associated STATE_COUNTY's belonging to this country along with the DATE_LAST_VISITED and POPULATION for each STATE_COUNTY_CODE.
-------------> All the associated TOWN_CODE's belonging to this state_county and country along with the DATE_LAST_VISITED and population for each TOWN.
So the table will have 9 columns:
COUNTRY
DATE_LAST_VISITED_COUNTRY
POPULATION_COUNTRY
STATE_COUNTY
DATE_LAST_VISITED_STATE_COUNTY
POPULATION_COUNTY
TOWN
DATE_LAST_VISITED_TOWN
POPULATION_TOWNAny ideas how this can be done?
Thanks.Hi guys,
Would it be ok to do it like this (with a join):
SELECT
c.country_code,
c.date_last_visited AS DATE_LAST_VISITED_COUNTRY,
c.population AS POPULATION_COUNTRY,
s.state_county_code,
s.date_last_visited AS DATE_LAST_VISITED_STATE_COUNTY,
s.population AS POPULATION_COUNTY,
t.town_code,
t.date_last_visited AS DATE_LAST_VISITED_TOWN,
t.population POPULATION_TOWN,
FROM
country c
LEFT OUTER JOIN state_county s ON s.country_code = c.country_code
LEFT OUTER JOIN town t ON t.country_code = s.country_code
AND t.state_county_code = s.state_county_codeThe results required would be something like:
Country_Code DATE_LAST_VISITED_COUNTRY POPULATION_COUNTRY STATE_COUNTY_CODE DATE_LAST_VISITED_STATE_COUNTY POPULATION_COUNTY TOWN_CODE DATE_LAST_VISITED_TOWN POPULATION_TOWN
UK 14-JAN-09 56,00000 London 18-JUL-99 23,0000 Ascot 30-JUN-89 12,000
Brixton 28-JAN-92 4,684
Birmingham 12-SEP-09 55,678 Solihull 12-OCT-81 6.768 Does this make sense?
Thanks!
Edited by: Sastry on Nov 2, 2009 2:04 AM -
Select statement for JDBC receiver synch scenario for capturing random value from ECC portal
Dear Experts,
I am working on ECC <----> SAP-PO 7.31 <----> JDBC synchronous scenario. I am clear about the config part except the Select statement. I will be
capturing 2 random values from the portal i.e. VendId and VendName in ECC to get the vendor details like Vendor Country, Vendor Status, Vendor Contact , Vendor Address etc from JDBC vendor table/view VENDETAIL.
What would be the select statement to capture the random values for ECC portal? My select statement would look some thing like this..
Select f1,f2,f3,f4 from table VENDETAIL where key1 = "VendId" and "VendName"
Please suggest if the above select statement works for the above scenario...
Regards
RebeccaHi Rebecca,
Your statement should work fine.
Please see the statement we use below.
SELECT eT_cashier, eT_proc_yn, eT_proc_date FROM eTest WHERE eb_proc_yn = 'N'
Just remember to update the change indicator so that you dont duplicate your records.
UPDATE eTest SET eb_proc_yn = 'Y' WHERE eb_proc_yn = 'N'.
Regards,
Jannus Botha -
Combining two single recordset into one two column recordset
Hi Forum
Assume we have three types , each 'table of'
CREATE OR REPLACE type type1 as table of number ;
CREATE OR REPLACE type type2 as table of varchar2 (255);
CREATE OR REPLACE TYPE TYPEVALUE AS OBJECT
(object_type number ,
object_value varchar2(255)
resultset1 type1 := type1() ;
resultset2 type2 := type2() ;
resultset3 typevalue := typeValue3() ;
I want to populate records of resultset3 from resultset1 and resultset2 , using resultset1 for first column of record and resultset2 for second column.
One way is to do for loop but I don't want to use this.
I need something similar to resultset3 to use it dynamically in select statement to do MINUS operation with another resultset . I think things like MULTISET, COLLECT, CAST can achieve what I want to do.
Can you please help me to have a select statement that combines two single column rowset and put into a two column recordset.
ThanksHi,
You can do something like this:
SQL> create or replace type type1 as table of number;
2 /
Type created.
SQL> create or replace type type2 as table of varchar2(255);
2 /
Type created.
SQL> create or replace type typevalue as object(object_type number, object_value varchar2(255));
2 /
Type created.
SQL> create type typevalue_tab as table of typevalue;
2 /
Type created.
SQL> ed
1 declare
2 resultset1 type1 := type1(1, 2, 3, 4, 5);
3 resultset2 type2 := type2('one', 'two', 'three', 'four', 'five');
4 resultset3 typevalue_tab;
5 begin
6 for l_res in (
7 select typevalue(t1.col1, t2.col2) as col
8 from (
9 select column_value col1
10 , rownum rn
11 from table(cast(resultset1 as type1))
12 ) t1
13 , (
14 select column_value col2
15 , rownum rn
16 from table(cast(resultset2 as type2))
17 ) t2
18 where t1.rn = t2.rn
19 )
20 loop
21 dbms_output.put_line(
22 'Object Type: '||l_res.col.object_type||' '||
23 'Object Value: '||l_res.col.object_value
24 );
25 end loop;
26* end;
SQL> /
Object Type: 1 Object Value: one
Object Type: 2 Object Value: two
Object Type: 3 Object Value: three
Object Type: 4 Object Value: four
Object Type: 5 Object Value: five
PL/SQL procedure successfully completed.All the work here is done in SQL so it should work similarly if you have these things defined as nested table columns in the database.
However, there is a caveat here: the lines highlighted in bold above are defining an arbitrary ordering for the nested table elements using rownum, as there is no concept of ordering within a nested table. You should change this part of the query to whatever makes sense in your environment, otherwise this solution cannot be guaranteed to be correct. Another option would be to use VARRAYs, as they will retain the order of elements.
cheers,
Anthony -
How can we Restict the Char single value Variables with , , =
Hi Experts,
How can we Restict the Char value Variables with <, >, <= (without selecting Inverval or only passing single value)
For Example
We have a standard Query 0FIAR_C03_Q1005, in this
New Selection
"1 - 15 Days, Posting Date<=Key Date, Clearing Date>Key Date"
This is restricted with the
Clearing(0CLEAR_DATE)
<Clearing key date(0P_KEYD3) It is a single value SAP Exit Varible
PostingDate(0PSTNG_DATE)
<= Posting keydate(0P_KEYD3) It is a single value SAP Exit Varible
When seeing these 0P_KEYD3, 0P_KEYD3 variables in the New selection screen they looks like >0P_KEYD3, <=0PSTNG_DATE
if you define any custom variables these are looks like =ZV_DATE.
to enable < , >, <= symbols for variables what we need to do.
In other way
Say we created one variable ZV_DATE single value, processing type as customer exit.
for this we populated current day,
Now Requirement is we need to display the all the records which are <= current date,
instead of passing low and high values, i want to restrict the calday <=ZV_DATE
New selection
0calday
<=ZV_DATE
How can we achive this, this is how the business content report having the restrictions
Please sugget me.
Thanks
Chandra
Edited by: Chandra Gandla on Jun 18, 2010 11:01 AM
Edited by: Chandra Gandla on Jun 18, 2010 11:01 AMOk,
In the InfoObject 0calday in the query designer under the filter area, under characteristic restrictions right-click over that InfoObject (0calday).
In the next window (select Values for [0CALDAY] Calendar Day in the dropdown box for "Show" choose Value Ranges. Under the word "Between" dropdown box select "Less than or equal to"
Below that word click on the button of the dropdown box Select from list.
In the new window select instead of History Variables and double-click on your variable ZV_DATE.
Click on the right blue arrow to move it to the right.
And there you go.
Tip: It exists a SAP standard variable named 0DAT which is exactly the current date (don't need to use ZV_DATE variable).
Diogo. -
Selection in the Infopackage for multiple values...
In the Selection package of the Infopackage(full mode) , I want to restrict the selection of the data to three values out of all the values.
Is it possible.
I cant give it in the From and To , its not in sequence.
The field for which I want to select the data is Material Type.
Please let me know.
Thanks , jeetuHi,
You can enter multiple single valus for any field in the infopackage. Just select the row for material type and then click on the insert duplicate button ( + sign ) which is at the bottom letf hand side in the 'Data Selection' tab within the infopackage. You will usually find this 'insert duplicate' icon next to the 'Check' push button.
You can insert as many rows as you want for material type by select the material type rown and clicking on this icon. You can then enter the three values in the three rows for material type.
Regards,
Shilpa -
Multiple single values variables in cockpit not possible ??
Hi,
I'm trying to create a variable in SEM-CPM-MC, but no matter what I do, I'm only able to create a runtime variable with selection type P - Variable for single value. I can select the other values, but when I save the variable, SAP automatically corrects it to P - Singe value again. I can also create a design variable with the other types, but not a runtime variable. How do I create a variable for which you can enter an interval/multiple single values?
In the documentation it also says, that you should be able to create variables on a frame level. I don't see any button where I can create a variable on a frame level. I've done exactly as it says on help.sap.com, but I don't have a button to create a new variable on a frame level. How do I do that?
Any help is appreciated and will be rewarded generously :o)
Thanks,
rameshHi Goutham R,
As of 4.0. it was by a limitation.
I have read some where that some users were able to meet the requirement by putting a semi colon at the end of each value in a excel and feeding it to the prompt but seems like you have already tried that.
Please see if you put a vote here in this link:
Selection option variable not behaving the same way in WebI : View Idea
But I think this requirement can be met in Analysis edition for OLAP.
BR
Prabhith
Maybe you are looking for
-
How do i remove incontext editing to allow contribute to work
Hi, I am hoping someone maybe able to help... A while ago I put a site together at applied incontext editing regions. After being notified that it will no longer work in May this year, I decided to purchase contribute and went through the labourious
-
Update VEKP-EXIDV2 during automatic HU creation from outbound delivery
Hi All, I need your suggestion / input on following scenario. When I create an outbound delivery and save it, an automatic Transfer Order is created and at the same time an HU is created for delivery. Now, I want to populate the field VEKP-EXIDV2 ( H
-
Uploading a web page that I have designed myself
Forgive me asking this but I am newbie to Macs and are slowly unraveling this wonderfull concept. I have checked out the templates that iWeb provides and I would like to design my own and upload them. I have looked and cannot find any reference to do
-
Generic delta for master data table MEAN
Hello all, How should the settings for my generic data source look? It's masterdata attributes and I'd like it to be delta compatible. The basis for the data source is table MEAN in R/3. Could someone please specify the settings that should be applie
-
Can I programmatically change the VI Search Path?
I'm writing a simple program to periodically mass compile certain directories of my source code. In my directory structure I try to enforce rules about what is allowed to depend on what, so I want to programatically enforce this during the mass comp