How to write the below query with parameter and is null
Hi, I need to retrive the data if the parameter is passed on the field, else retrive all records whose field is null
Example
CREATE TABLE DEPT
(DEPTNO NUMBER(2),
DNAME VARCHAR2(14),
LOC VARCHAR2(13) );
INSERT INTO DEPT VALUES (10, 'ACCOUNTING', 'NEW YORK');
INSERT INTO DEPT VALUES (20, 'RESEARCH', 'DALLAS');
insert into dept values (30, 'SALES', 'CHICAGO');
INSERT INTO DEPT VALUES (40, 'OPERATIONS', 'BOSTON');
alter table dept add(object_id number);
insert into dept values (50, 'OPERATIONS', 'BOSTON',1);
insert into dept values (60, 'OPERATIONS', 'BOSTON',1);
INSERT INTO DEPT VALUES (70, 'OPERATIONS', 'BOSTON',2);
select * from dept where object_id =:p_object_id
If i pass the object_id as 1 , it shloud retrive the values of dept with object_id 1, but if i dont pass the object_id, it should retrive all the records whose object_id is null
IF 1 is passed, as object id , it should retrive, 50, 60, if 1 is not passed as object_id it should retive 10,20,30,40
It works fine for me seperately as,
select * from dept where object_id =:p_object_id -- 1
select * from dept where object_id is null;
Is this possible to do in single query.
Thanks
SELECT *
FROM dept
WHERE object_id = :p_object_id
OR (object_id is null and :p_object_id is null)
is one approach. It's a bit verbose but the meaning is clear. If you can identify a value that would never appear in the data (-1 for example)
WHERE nvl( object_id, -1 ) = nvl(p_object_id, -1 );
Justin
Similar Messages
-
How to write the select query with complex where condition
Hi all,
Can u help me in writing following select query.
select * from zu1cd_corr where time_stamp between firstday and lastday .
In the above query time_stamp contains the date and time.
where as firstday and lastday contains the dates.
I need to compare the date in the time_stamp with the firstday and lastday.
But time_stamp contains the time also and it is char of 14 characters length.Hi,
If that is the case u can do as advait specified....
if the firstday and secondday are select-options then declare two more variables having 14 character length and then concatenate '000000' to firstday variable and '240000' to last day variable and then write ur query.
CLEAR : lv_firstday,
lv_lastday.
concatenate firstday '000000' to lv_firstday.
concatenate lastday '240000' to lv_lastday.
ranges : r_Date for zu1cd_corr-time_stamp.
r_date-sign = 'I'.
r_date-option = 'BT'.
r_Date-low = lv_firstday.
r_Date-high = lv_lastday.
append r_date.
select * from zu1cd_corr into table it_zu1cd_corr where time_stamp in r_Date.
I hope it helps.
Regards,
Nagaraj -
How to write the given query using 'ANY ' operator
Hi,
How to write the given query using 'ANY ' operator , I dont need to fetch to grade_master table twice in database, just need to fetch within the result set.
SELECT dsg_code,dsg_name,dsg_grade FROM designation_master WHERE dsg_orgn='&&Orgn' and dsg_ctry='&&ctry'
And dsg_loc ='&&loc' And dsg_oru = '&&oru' and dsg_grade in decode('&&radio_group',
1, SELECT grd_code FROM grade_master WHERE grd_osm_code in (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&Orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'),
2, SELECT grd_code FROM grade_master WHERE grd_osm_code > (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' and grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code),
3, SELECT grd_code FROM grade_master WHERE grd_osm_code < (Select grd_osm_code FROM grade_master WHERE grd_orgn='&&orgn' and grd_ctry='&&ctry' And grd_loc ='&&loc' And grd_oru = '&&oru' and grd_code ='&&emp_grade'))
thanks
rincyHi,
One thing I understood my your issue is you want to perform, execution of query once or fetch the results sets my minimizing the number of times executions of queries. It would be hard for us to check in this way, atleast provide some temporary data and some business rules. Only I can IN, >, < (queries logical conditons on inner query)
- Pavan Kumar N
- ORACLE OCP - 9i/10g
https://www.oracleinternals.blogspot.com -
How to write XSJS Select Query with input parameters
Hello Experts,
I am creating a xsjs file and in that file I am trying to write a Select Query based on a Calculation View
I have tried it the following way:
var query = 'SELECT TOP 100 \"Name\", \"Address\", \"City\", \"Country\" FROM \"_SYS_BIC\".\"Test.HL/AddressView\"'
+ 'WITH PARAMETERS(\'PLACEHOLDER\' = (\'$$P_Name$$\', \' Akhil \'),'
+ '\'PLACEHOLDER\' = (\'$$P_City$$\', \' Lucknow \'))';
But it gives me the "Mixed spaces and tabs error".
How should I write XSJS Select Query with input parameters?
Regards,
Rohit>But it gives me the "Mixed spaces and tabs error".
Mixed spaces and tabs has nothing to do with the syntax of the statement. You used both spaces and the tab in the content - which JSLint doesn't like. Remove the beginning spaces of each line and use only one or the other.
The actual syntax of your statement doesn't look right. The problem is that you are escaping the \ when you don't need to if you are using ' instead of " for your string. You escape with \" in the first line but then escape with \' in the 2nd and 3rd line. That is going to cause serious parsing problems with the command. -
How to write the dynamic code for RadioGroupByKey and Check Boxes?
Hi,
Experts,
I have created a WD ABAP application in that i have used RadioGroupByKey and CheckBox Ui elements but i want how to write the dynamic code to that i want to display male and female to RadioGroupByKey and 10 lables to check boxs.
Please pass me some idea on it and send any documents on it .
Thanks in advance ,
Shabeer ahmed.Refer this for check box:
Do check :
bind_checked property is bind to a node with cardinality of 1:1
CHECK_BOX_NODE <---node name
-CHECK_BOX_VALUE <--attribute name of type wdy_boolean
put this code under your WDDOMODIFYVIEW:
DATA:
lr_container TYPE REF TO cl_wd_uielement_container,
lr_checkbox TYPE REF TO cl_wd_checkbox.
get a pointer to the RootUIElementContainer
lr_container ?= view->get_element( 'ROOTUIELEMENTCONTAINER' ).
lr_checkbox = cl_wd_checkbox=>new_checkbox(
text = 'WD_Processor'
bind_checked = 'CHECK_BOX_NODE.CHECK_BOX_VALUE'
view = view ).
cl_wd_matrix_data=>new_matrix_data( element = lr_checkbox ).
lr_container->add_child( lr_checkbox ).
Refer this for Radiobutton :
dynamic radio button in web dynpro abao
Edited by: Saurav Mago on Jul 17, 2009 10:43 PM -
hi Guys,
i make the application, in which lots of data record with id, whenever i clicked to the SUBMIT button, it wil forwarded to the next page.
But The problem is.....when we pass the 30 id in a query string parameter that' fine but when it is incresing it is not transfaring to the next page. how i can do this.
As per the concept EVERY BROWSER HAVING THE LIMITATION..
hope all of u help me.
saMhey all of you are saying right..!!
But you know the doPost() method having the limitation, that is
1 MB. so how can i used this method.
I know the second way....Like make the hidden control with mantain the session, but i can not use this(Client do't want this).
so please guys help me........
saM -
How to write EJB-QL query with IN notation and list values EJB3.0?
hi,
I would like to write an EJB-QL query where the query would return the objects whose name equals to one of the names in the list.
SELECT DISTINCT OBJECT(feature) FROM MAPSHEET_LOCK feature WHERE feature.name IN ?1
For ?1 I would like to pass in a list. How can I write this query?
ThanksList<String> names;
StringBuilder sb = new StringBuilder("SELECT DISTINCT OBJECT(feature) FROM MAPSHEET_LOCK feature WHERE feature.name IN (");
String separator = "";
for (String name : names) {
sb.append(separator);
sb.append("'");
sb.append(name);
sb.append("'");
separator = ", ";
sb.append(")");
String ejbql = sb.toString();
// Code for execute query
....Message was edited by:
Rulas -
How to tune the below query?is taking 1min 15 sec to process 16,34,300 reco
SELECT
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt);Do you have multiprocessor CPU .
if the value is greater then 3 then you can try with parallel processing
select value from v$parameter where name ='cpu_count' ;Try this :-
ALTER SESSION ENABLE PARALLEL QUERY
SELECT /*+ parallel (a) */
user_id,
ispeak,
round(sum(DURATION_seconds*convert_duration(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(download_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(ratingunit),
round(sum(upload_bytes*convert_bytes(pulseunit,ratingunit))/decode(ispeak,0,max(offpeakpulse),max(peakpulse))),
max(packageid),
max(peakrate),
max(offpeakrate),
max(bstplantype),
max(freevalue),
max(peakpulse),
max(offpeakpulse),
max(pulseunit),
max(ratingunit),
min(start_time_utc) ,
max(end_time_utc),
min(srt.activedt),
min(srt.inactivedt)
FROM aaa_sessions a,subscriber_rate_tab srt
where
a.user_id=srt.externalid(+)
group by user_id,packageid,ispeak
having
trunc(min(start_time_utc)) between min(srt.activedt) and min(srt.inactivedt)
and
trunc(max(end_time_utc)) between min(srt.activedt) and min(srt.inactivedt)Cheers
Nawneet
Edited by: Nawneet_Aswal on Aug 2, 2010 4:48 AM -
How to write the SQL query for generating triangular numbers
Hi,
I have a table ..which stores the sequence number like this
Seq :
1000
1200
1300
1500
1800
1900
Now i want to get a result like this
1000 1000
1200 2200
1300 3500
1500 5000
1800 6800
1900 8700
how can it be achieved. I tried using Lead and lag. but only I can add the n+1 or n-1 results. Please help.I've never heard it called 'triangular numbers' before but I think you're looking for a 'running total':
SQL> WITH data AS
2 (
3 SELECT 1000 AS num FROM dual UNION ALL
4 SELECT 1200 AS num FROM dual UNION ALL
5 SELECT 1300 AS num FROM dual UNION ALL
6 SELECT 1500 AS num FROM dual UNION ALL
7 SELECT 1800 AS num FROM dual UNION ALL
8 SELECT 1900 AS num FROM dual
9 )
10 /* END SAMPLE DATA */
11 SELECT num, SUM(num) OVER (ORDER BY num) AS running_total
12 FROM data
13 ORDER BY 1
14 ;
NUM RUNNING_TOTAL
1000 1000
1200 2200
1300 3500
1500 5000
1800 6800
1900 8700
6 rows selected. -
SQL QUERY How to write a sql query with a complex where clause.
I would like to get a list of all my invoices from the past year plus any open invoices that are more than a year old.
I don't want any overlapping rows.
Debra has a questionDebra,
Sorry but you have posted to a forum that deals exclusively with questions/issues about customizing and programming Microsoft Project, a planning and scheduling application. I suggest you delete this post and find a more appropriate forum.
John -
How i map the caf data with data of UWL in web dynpro
Hi Experts,
i created a bpm project with nwce 7.1.1 and it have a independent caf to keep it's data and status.
now i have to create a view(use web dynpro) such like UWL,
my question is
how i map the caf data with UWL, and let the view can open the task(popup a window, just like UWL do) for user to finish their job?
thanks.Hi Vic
Your requirement is exect functionality of UWL based on WEBDYNPRO, CAF and BPM for automation? ,and question is How to use CAF with WD or CAF with UWL API's ?. please clarify it.
Please fo through from given doc misght give u some idea
1. [How to develop Web Dynpro UI for your CAF project |http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417300)ID0722080650DB02400261803144436507End?blog=/pub/wlg/5414]
Best Regards
Satish Kumar -
Sql query with conditions and calculations???
Hi,
how I can build a query with conditions and calculations?
E.g. I've got this table
Start | End | Working Place | Mandatory
01-JAN-13 | 11-JAN-13 | Office | 1
14-JAN-13 | 25-JAN-13 | Home Office | 0
04-MRZ-13| 15-MRZ-13 | Office | 0
11-FEB-13 | 22-FEB-13 | Office | 1
Now if column working place=Office and column mandatory=0
the new column "price" has to calculate: (End-Start)* $25.00
and if working place=Office and column mandatory=1
the "price" column has to calculate: (End-Start)* $20.60
else $0.00
I tried it with the case statement but I didn't know how
to calculate my values and display it to the virtual column "price".
Something like
case
when Working_Place = 'Office' and Mandatory=1
then ...
else '0.00'
end as PRICE
Or is it not possible?
Edited by: DB2000 on 12.03.2013 05:09Use CASE:
select start_dt,
end_dt,
working_place,
mandatory,
case
when working_place = 'Office' and mandatory = 0 then (end_dt - start_dt) * 25
when working_place = 'Office' and mandatory = 1 then (end_dt - start_dt) * 20.60
else 0
end price
from tbl
START_DT END_DT WORKING_PLA MANDATORY PRICE
01-JAN-13 11-JAN-13 Office 1 206
14-JAN-13 25-JAN-13 Home Office 0 0
04-MAR-13 15-MAR-13 Office 0 275
11-FEB-13 22-FEB-13 Office 1 226.6
SQL> SY. -
How to write a sql query to retrieve data entered in the past 2 weeks
Hi,
I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
Thanks in advance.This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate". -
How to write a SQL query in SAP B1 2007 B with input parameters?
How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?
The syntax like
SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
Thanks,
Gordon -
How can i write the below code using "For all entries"
Hi
How can we write the below code using "for all entries" and need to avoid joins...
Please help
SELECT aaufnr aobjnr aauart atxjcd a~pspel
agstrp awerks carbpl cwerks
INTO TABLE t_caufv
FROM caufv AS a
INNER JOIN afih AS b
ON aaufnr = baufnr
INNER JOIN crhd AS c
ON bgewrk = cobjid
AND c~objty = 'D'
WHERE ( a~pspel = space
OR a~txjcd = space
OR NOT a~objnr IN
( select OBJNR from COBRB AS e
WHERE objnr = a~objnr ) )
AND a~werks IN s_plant
AND a~auart IN s_wtype
AND NOT a~objnr IN
( select OBJNR from JEST AS d
WHERE objnr = a~objnr
AND ( dstat = 'A0081'OR dstat = 'A0018' )
AND d~inact 'X' ).
Reward points for all helpfull answers
Thanks
Ammi.Hi,
SELECT objnr objid aufnr
from afih
into table t_afih.
SELECT objnr
from JEST
into table t_JEST
where stat = 'A0045'
OR stat = 'A0046'
AND inact 'X'.
SELECT objnr
from COBRB
into table t_cobrb.
SELECT arbpl werks objid objty
from crhd
INTO table it_crhd
FOR ALL ENTRIES IN it_afih
WHERE objty eq 'D'
AND gewrk = it_afih-objid.
SELECT aufnr objnr auart txjcd pspel gstrp werks aufnr
FROM caufv
INTO table t_caufv
FOR ALL ENTRIES IN it_afih
WHERE aufnr = it_afih-aufnr
And pspel = ' '
AND txjcd = ' '
ANd objnr ne it_crhd-objnr
AND auart in s_wtype
AND werks in s_plant.
AND objnr ne it_jest-objnr.
dont use NE in the select statements, it may effect performance also. Instead use if statements inside
loops.
loop at t_caufv.
read table it_chrd............
if t_caufv-objnr ne it_chrd-objnr.
read table it_jest..........
if if t_caufv-objnr ne it_jest-objnr.
(proceed further).
endif.
endif.
endloop.
hope this helps.
Reward if useful.
Regards,
Anu
Maybe you are looking for
-
Outputing Raw Stream via airport express
What is the output of the airport express optical port? Is a raw stream of the original audio file? thx
-
Procedure for IP Address change in MSCS
Hi, I need to change the IP address of SAP server, which is configured with MSCS. Please let me know the procedure for changing IP address in MSCS environment. We are using 2 nodes Active-Passive cluster. Regards, Ranjith
-
Problems with QCM tables in DB export
Hi gurus, I have a problem with an export that I'm performing, the problem is that the R3SETUP is trying to export a QCM table "QCMT066" but this table doesn't exits in the database. (EXP) ERROR: DbSlExeRead: rc = 107, table "QCMT066" (SQL er
-
An Apple remanufactured Mac Pro purchased two months ago has locked its hard drive (possibly with help from a cat that walked across the keys). It won't accept our administrator password. We never noticed whether filevault or firewalls were set by Ap
-
Extra Cables. Is it for the remote?
I have a desktop s5750z. I bought it with the tv tuner and wireless options. My computer came with 2 extra cables that I do not know where they belong. It looks like one would be the remote sensor because there is a red sensor like thing at the end.