How to give date in where of select statement
hi
iam using this stmt SELECT AUFNR WERKS KDAUF KDPOS PLNBEZ GAMNG
GMEIN GSTRP GLTRP FROM CAUFV INTO TABLE TB_CAUFV
WHERE AUFNR IN S_AUFNR
AND KDAUF IN S_KDAUF
AND WERKS IN S_WERKS
AND GSTRP = V_DATE1.
AND GLTRP = V_DATE2.
this is not working.
v_date1 is of sy-datum.
plz sol me this
thanks and reg
viju
HI sriram,
can u check if the date is in the same format in table CAUFV as in sy-datum?
the date format in sy-datum is stored as yyyymmdd..check if the date for comparison is in the same format..or change
it to the format..of sy-datum
reward if useful
regards,
sampath
Edited by: sampath pilla on Jun 13, 2008 3:36 PM
Similar Messages
-
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
How to view data in tables by selecting the synonym from the database objec
I could not figure out how to view data in tables by selecting the synonym from the database objects navigation tree. I had to first choose the synonym, view the details of the synonym to determine the table name, and then select the table from the database objects tree. Is this the only way available?
This functionality currently does not exist. I don't see it on the 1.1 statement of direction either, so perhaps someone from Oracle can give some insight as to when this could be expected.
Eric -
How can I use a where in Select clause?
How can I use a where in select clasue when the other part of the where I do not not.
I mean that
Select *
from mara
where MATNR = MT*
That means it can have MTA, MTB, MTC....and so on
I can I write this code.
Regards,
Subhasishhiii
you can use following query
SELECT * FORM mara WHERE matnr CONTAINING 'MT'
or use following
select * from mara WHERE matnr = 'MT%'
reward if useful
thx
twinkal -
How to compile the hint to force selection statement to use index
Hello expert,
will you please tell me how to compile the hint to force selection statement to use index?
Many Thanks,Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
SQL> explain plan for
2 select * from emp
3 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 3956160932
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS FULL| EMP | 14 | 546 | 3 (0)| 00:00:01 |
8 rows selected.
SQL> explain plan for
2 select /*+ index(emp,pk_emp) */ *
3 from emp
4 /
Explained.
SQL> @?\rdbms\admin\utlxpls
PLAN_TABLE_OUTPUT
Plan hash value: 4170700152
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 14 | 546 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 14 | 546 | 2 (0)| 00:00:01 |
| 2 | INDEX FULL SCAN | PK_EMP | 14 | | 1 (0)| 00:00:01 |
9 rows selected.
SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
SY. -
How to increment variable value in single select statement
Hi guys
in this select statement i have hard coded date value but i need to put variable instead of hard coded date and then i want to increment that variable value till sysdate.. i have tried using curser , type tables but they are very very slow .. any experiance guys can give me good hint what should i use.
my query
select
start_dt,
end_dt,
hi_start_dt,
hi_end_dt,
ph_start_dt,
ph_end_dt,
h_start_date,
h_end_date,
g_code,
emp_det.ref,
u_code,
costing,
emp_nm,
emp_no
from
emp_det,
emp_ph_det,
emp_hi_det,
emp_h_det
where
emp_det.ref(+) = emp_ph_det.ref
and emp_hi_det.p_ref(+) = emp_ph_det.p_ref
and emp_h_det.ph_ref = emp_ph_det.ph_ref
and emp_h_det.ph_st_dt(+) = emp_hi_det.st_date;
and to_date('01-MAR-2008') between i.start_dt and nvl(i.end_dt, to_date('01-MAR-2008') +1)
and to_date('01-MAR-2008') between i.hi_start_dt and nvl(i.hi_end_dt, to_date('01-MAR-2008') + 1)
and to_date('01-MAR-2008') between i.ph_start_dt and nvl(i.ph_end_dt, to_date('01-MAR-2008') + 1)
and to_date('01-MAR-2008') between i.h_start_date and nvl(i.h_end_date, to_date('01-MAR-2008') + 1)
or
(----emp has left this month
i.start_dt < i.emp_end_dt
and i.end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.hi_start_dt < i.hi_end_dt
and i.hi between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.ph_start_dt < i.ph_end_dt
and i.ph_end_dt between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')
and i.h_start_date < i.h_end_date
and i.h_end_date between add_months(to_date('01-MAR-2008'), -1) + 1 and to_date('01-MAR-2008')Hi Anurag
Thanks for the reply.please find my sample data below . below i am only showing data for one employee only.. i want to write a query where i will query for a month like march 2008 and then i need to find out the record for employe where this month march 2008 is between all the start and end dates like it should be between start_dt and end_dt and h_start_date and h_end_date and hi_strt_dt and hi_end_dt and ph_start_dt and ph_end_dt and where all the combination are true show me that record only .. i don't want any other record.
h_start h_end_
start_dt end_dt date date histrt_dt hi_end_dt ph_start_dt ph_end_dt
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Sep-07 31-Dec-07 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Aug-08 31-Aug-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Aug-08 31-Aug-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Aug-08 31-Aug-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Oct-08 31-Dec-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Oct-08 31-Dec-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Oct-08 31-Dec-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 1-Sep-08 30-Sep-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 1-Sep-08 30-Sep-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 1-Sep-08 30-Sep-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 8-Feb-08 31-Aug-08 8-Feb-08 31-Jul-08 8-Feb-08 31-Dec-08
1-Sep-07 31-Dec-08 1-Sep-07 31-Dec-07 8-Feb-08 31-Jul-08 1-Sep-07 31-Dec-07
1-Sep-07 31-Dec-08 1-Sep-08 31-Dec-08 8-Feb-08 31-Jul-08 8-Feb-08 31-Dec-08 -
How to use variables in an sql select statement.
Hi, I have seen examples using the update, but nothing using a select statement.
I have four variables I am getting from drop down menus in my JSP I set the user selected items to strings.
How would I create the select statement like this:
.String XName = request.getParameter("UserInputX");
rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = XName")Obviously it tries to read "XName" as a column and of course can't find it, how would I set it up to have it see the Value of XName and not the literal XName.read this:
rsInResult = stmtInResult.executeQuery("SELECT ColumxX FROM TableZ WHERE ColumnX = '"+XName+"')
{code}
better way is PreparedStatement:
{code}
// example code to change password to an user in the USERS table
String newPWD = "my password";
String user = "luxjava";
PreparedStatement prepStat;
String updatePWD = "UPDATE LOGISTIC.USERS "+
"SET logistic.users.password = ? "+
"WHERE logistic.users.username = ?";
prepStat = ql.conDb.prepareStatement(updatePWD);
prepStat.setString(1, newPwd);
prepStat.setString(2, user);
int zeroNotFound = prepStat.executeUpdate();
if (zeroNotFound==0)
ql.conDb.rollback();
prepStat.close();
else
ql.conDb.commit();
prepStat.close();
{code}
... use the SQLException to capture errors -
In how many ways we can filter this select statement to improve performance
Hi Experts,
This select statement taking 2.5 hrs in production, Can we filter the where condition, to improve the performance.Plz suggest with coding ASAP.
select * from dfkkop into table t_dfkkop
where vtref like 'EPC%' and
( ( augbd = '00000000' and
xragl = 'X' )
or
( augbd between w_clrfr and w_clrto ) ) and
augrd ne '03' and
zwage_type in s_wtype .
Regards,
Sam.if it really takes 2.5 hours, try the followingtry to run the SQL trace and
select *
into table t_dfkkop
from dfkkop
where vtref like 'EPC%'
and augbd = '00000000' and xragl
and augrd ne '03'
and zwage_type in s_wtype .
select *
appending table t_dfkkop
from dfkkop
where vtref like 'EPC%'
and augbd between w_clrfr and w_clrto
and augrd ne '03'
and zwage_type in s_wtype .
Do a DESCRIBE TABLE after the first SELECT and after the second,
or run an SQL Trace.
What is time needed for both parts, how many records come back, which index is used.
Siegfried -
How do you include static text in select statement in Dynamic pl/sql
I want to include some atatic text and get the output of 4 columns joined with a ":" delimiter within them in a select statement built using Dynamic PL/SQL. How do I build it.
e.g.
Normal select statement would be
select 'MY SKU IS : ', col1||':'||col2||':'||col3||':'||col4 from table1 where ....where condition
and output looks like :
MY SKU IS A:B:C:D
MY SKU IS a:b:c:d
Dynamically I have -
SQL_Stmt := 'select 'MY SKU IS : ', col1||':'||col2||':'||col3||':'||col4 from table1 where '|| wherecondition;
I understand that this does not work because the single quote terminates the string. But my question is how do I achieve the same result with dynamic PL/SQL ? How do I include the static strings and the delimiters. I have tried using double quote, '\'....
????SQL_Stmt := 'select ''MY SKU is ' || col1 || '':'' ||
col2 || '':'' ||
col3 || '':'' ||
col4 ||
' from table1 where ' || wherecondition; -
Retrieve floating point data with an sql select statement
Hi
I'm quite new to using sql but I have a system working where I can read and write strings to an access database.
Now I want to retrieve a a float, from a field where another field in the same post corresponds to a specified float, with a select statement.
When using strings I wrote
SELECT column_name FROM [table_name] WHERE column2_name='value'
in my query.
But instead of getting the desired value I get an error message telling me that I have a
"Data type mismatch in criteria expression".
I think I understand why but does anybody know what I should have written instead?Is the data type of column2_name String? If it's not, I think the single-quotes you have around 'value' will cause that error.
Jim
You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice -
How to create MIN/MAX limitations in SELECT statement ??
Hey,
I have a table which rank90 (city population ranked from 1>*) and state_abrv which has the corresponding state for each city rank.
Is there a way to select only the maximum AND minimum ranks for each state ??
I realise there is a max and min function, but i need to do it for EACH state_abrv.
An example say Los Angeles is ranked 2, San Diego is ranked 6, and San Fransico is ranked 14 (All of these citys are in california (CA)). How do i display a table which lists only Los Angeles (Highest rank) and San Fransico (lowest rank) but DOESNT list San diego ??
Thanks, you guys are helping me heaps and im starting to learn a lot more :P
Message was edited by:
user495524SQL> create table t (state varchar2(2), city varchar2(20), n number);
Table created.
SQL> insert into t values ('CA','San Francisco',14);
1 row created.
SQL> insert into t values ('CA','San Diego',6);
1 row created.
SQL> insert into t values ('CA','Los Angeles',2);
1 row created.
SQL> insert into t values ('NY','Buffalo',4);
1 row created.
SQL> insert into t values ('NY','Syracuse',7);
1 row created.
SQL> insert into t values ('NY','Mt Kisco',2);
1 row created.
SQL> insert into t values ('NY','Albany',5);
1 row created.
SQL> select * from t order by state, n desc;
ST CITY N
CA San Francisco 14
CA San Diego 6
CA Los Angeles 2
NY Syracuse 7
NY Albany 5
NY Buffalo 4
NY Mt Kisco 2
7 rows selected.
SQL> select state, city, n from
2 (
3 select t.*, min(n) over (partition by state) min_n,
4 max(n) over (partition by state) max_n from t
5 )
6 where n in (min_n, max_n) order by state, n desc;
ST CITY N
CA San Francisco 14
CA Los Angeles 2
NY Syracuse 7
NY Mt Kisco 2
SQL> -
How to JOIN the results of multiple SELECT statements
Hello,
I currently have a table where each row represents a single census date for a given tag number, where each tag number can have multiple census dates and data which are represented by their own row in the table.
I currently have 2 SELECT statements that select all tag numbers given a census date, and would like to combine those 2 queries so that the data is presented in a manner such that for each tag number, instead of obtaining 2 rows for each tag number, I would be presented with 1 row for each tag number consisting of three columns: tag_number, data1, and data2.
Both of the requested dates are not necessarily present for all tag numbers, and in the event that only one date is present, the other column should contain null, but if both dates are not present for a given tag number, the tag number is omitted.
The two queries I would like to JOIN are:
SELECT a.tag_number, a.data AS data1
FROM tab1 a
WHERE
a.census_date='11/21/2009'and
SELECT b.tag_number, b.data AS data2
FROM tab2 b
WHERE
b.census_date='11/24/2009'The table from which I am selecting the data looks like such:
tag_number census_date data
1 11/21/2009 10
1 11/23/2009 11
1 11/24/2009 12
2 11/19/2009 13
2 11/21/2009 14And the data that I would like to result looks like:
tag_number data1 data2
1 10 12
2 14 nullAny help would be greatly appreciated.
Thank you in advance,
-Justin
Edited by: m8r-qbkka9 on Nov 24, 2009 4:17 PMHi,
This looks like a job for pivot
SELECT a.tag_number
, MAX (CASE WHEN a.census_date = TO_DATE ('11/21/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data1
, MAX (CASE WHEN a.census_date = TO_DATE ('11/24/2009'
'MM/DD/YYYY'
THEN a.data
END
) AS data2
FROM tab1 a
WHERE a.census_date IN ( TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
, TO_DATE ( '11/21/2009'
, 'MM/DD/YYYY'
GROUP BY a.tag_number
;Comparing DATEs to stirngs, like '11/24/2009', is simply asking for trouble.
Always use a conversion function (like TO_DATE) or DATE literals instead. -
How to use bind variable in this select statement
Hi,
I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
the procedure is given below:
create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
authid current_user
is
type poicurtype is ref cursor;
poi_cur poicurtype;
sqlst varchar2(250);
THEVALUE NUMBER;
begin
sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
DBMS_OUTPUT.PUT_LINE(SQLST);
OPEN POI_CUR FOR SQLST ;
LOOP
FETCH POI_CUR INTO THEVALUE;
EXIT WHEN POI_CUR%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(THEVALUE);
SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
SQLST:=SQLST|| ' WHERE EMPNO=:X';
DBMS_OUTPUT.PUT_LINE(SQLST);
EXECUTE IMMEDIATE SQLST USING THEVALUE;
END LOOP;
COMMIT;
END TEST;
Best Regards,So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
create or replace procedure test (tablename in varchar2, fieldname in varchar2)
authid current_user
is
sqlst varchar2 (250);
thevalue number := 1234;
begin
sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'') where substr(' || fieldname
|| ',1,5) = ''.THE ''';
dbms_output.put_line (sqlst);
execute immediate sqlst;
end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows. -
How: making column value as column of select statement
Hi
Quickly I have searched in this forum for following solution but not able to find it.
I need to make a query in such a way that the value of one column in one table should act as a column-name of another table
Eg:-
tab1
col1,col2,*col3*,col4
tab2
col11 col22 col33 col44
row1 a b col3 d
row2 aa bb cc dd
So the query should be something like --- in row2 if the value is col3 then from tab1 I should pick the col3 in select statement (basically there will be some join in tab1 and tab2 )
Hope I am able to make u all understand my query.
regardsHi all,
Sorry for late response.Just now I checked all the replies.
Actually I tried in this way.
CREATE OR REPLACE function Proc_caption (in_tan varchar2, in_order in number)
return varchar2
is
d varchar2(100) ;
begin
SELECT col1 into d
from tab1
Where
col2 = in_tanid
AND col3 = 'Y'
AND col4 = in_order ;
return d ;
Exception
WHen No_DATA_FOund then
return 'N' ;
end ;
create or replace procedure proc_generate_view(in_tan varchar2, in_soc varchar2)
is
x varchar2(2000);
v4 varchar2(50) ;
v5 varchar2(50) ;
cnt number ;
begin
v4:= PROC_Caption (in_tan,4) ;
v5:= PROC_Caption (in_tan,5) ;
x := ' Create view v_generate as '
|| ' SELECT a , b, c, d ' ;
if v4 <> 'N' THEN
x := x || ' , ' || PROC_Caption (in_tan,4) || ' as Caption4 ' ;
end if;
if v5 <> 'N' THEN
x := x || ' , ' || PROC_Caption (in_tan,5) || ' as Caption5 ' ;
end if;
x := x || ' FROM tab2 WHERE col1 = ''' || in_socid || ''''
|| ' AND col2 = ''' || in_tan || '''' ;
select count(1) into cnt from USER_OBJECTS where OBJECT_NAME = 'V_GENERATE'
and OBJECT_TYPE = 'VIEW' ;
if cnt > 0 then
EXECUTE IMMEDIATE ' DROP view V_GENERATE' ;
END IF ;
execute immediate x ;
end ;
NOTE:- I have just renamed the table name and column names in order to make it non confedential...
I have created this successfully with actual table name and column names and able to get the result as per my requirement.
regards -
How to : rownum and order by in select statement
Say I have a select statement with additional 'order by' clause.
The result set I want prepended by the rownum column.
But, and here comes the flaw, I want the rownum for the already ordered result set
not the unordered.
An example:
select firstname, lastname from myTable order by lastname;
When I add the rownum to the select clause,
'select rownum, firstname, lastname from myTable order by lastname;'
I might get something like:
20 Mike Adams
13 Nina Bravo
1 Tom Charlie
But I want the following result:
1 Mike Adams
2 Nina Bravo
3 Tom Charlie
I could now
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname);
But I guess there is a better way!?!
which is the best way to accomplish that?
Thanks for your advice!>
'Select rownum, lastname, firstname from (select firstname, lastname from myTable order by lastname)
>
Well if you ask me there is very little difference between this query and the above query
select rownum, lastname, firstname from mytable;Because rownum is assigned before the order by. The difference is in your query you are assigning a rownum to an ordered resultset but still there is no guarantee oracle is going to read the data in an ordered fashion. In the second query rownum is assigned to an unordered resultset. Again it is the samething. So if you want to guarantee it then I will go for the following option
select row_number() over(order by lastname) rn, lastname, firstname from mytable
order by lastnameAlso check this link.
http://www.oracle.com/technology/oramag/oracle/07-jan/o17asktom.html
Regards
Raj
Edited by: R.Subramanian on Jan 13, 2009 6:20 AM
Maybe you are looking for
-
Iphone 4 4.2.1 upgrade
Hey guys, i have a iphone 4 with version 4.2.1 and i want to update with a new version but without the ios 7...i've try it to search on google but all i find is only jailbreake...i don't whant to jail! all i need is the apps whatsapp, facebook, viber
-
I changed to firefox because I wanted spell checker. After updating to 4.0.1 this no longer works. I cant find a version that does work with the new firefox. Is it time i went back to explorer?
-
Hi All, How to find out the query created in which system like Dev or ACC or Prod. For ex. I want to find the queries directly created in Production.
-
Payer change at Billing document Header
Hi Is it possible to change the "Payer " partner at billing document header once the billing has been created and not posted to accounting? if so how? Regards
-
Hi, In my application user selects the file path using html file select and saves it. Other users should be able to open that file by just clicking that saved file path (i display it as a link). Now the problem is user maps the shared folder in netwo