Small Query help
small query i have data like below ,
Month ProductNo CustomerNo Units
Jan 9001 1001-09 100
jan 9002 1002-09 200
jan 9003 1003-09 300
jan 9001 ABCCustomer 400
Jan 9002 1004-09 500
for any record - if column - customerNo starts with numeric it has to show like CN_****** other wise the same name.
Result should be
Jan 9001 CN_1001-09 100
jan 9002 CN_1002-09 200
jan 9003 CN_1003-09 300
jan 9001 ABCCustomer 400
Jan 9002 CN_1004-09 500
Can some one help to get the query
Hi,
try this,
SQL> select *from v$version;
BANNER
Personal Oracle Database 10g Release 10.1.0.2.0 - Production
PL/SQL Release 10.1.0.2.0 - Production
CORE 10.1.0.2.0 Production
TNS for 32-bit Windows: Version 10.1.0.2.0 - Production
NLSRTL Version 10.1.0.2.0 - Production
1 with t as
2 (select 'Jan' Month ,9001 ProductNo, '1001-09' CustomerNo, 100 Units from dual
3 union all
4 select 'jan', 9002 ,'1002-09', 200 from dual
5 union all
6 select 'jan', 9003, '1003-09', 300 from dual
7 union all
8 select 'jan', 9001, 'ABCCustomer', 400 from dual
9 union all
10 select 'Jan', 9002, '1004-09', 500 from dual)
11 select Month,ProductNo,(case when regexp_like(customerno,'^[[:digit:]]') then
12 'CN_'||CustomerNo
13 else
14* CustomerNo end)cudtomer_no, units from t
SQL> /
MON PRODUCTNO CUDTOMER_NO UNITS
Jan 9001 CN_1001-09 100
jan 9002 CN_1002-09 200
jan 9003 CN_1003-09 300
jan 9001 ABCCustomer 400
Jan 9002 CN_1004-09 500or
regexp_like(customerno,'^[0-9]')or
regexp_like(customerno,'^[0123456789]')Edited by: user291283 on Sep 12, 2009 8:22 AM
Edited by: user291283 on Sep 12, 2009 9:24 AM
Similar Messages
-
Small query i Need ...
hi
i need a small query..
here four columns are there..
i want to need .between in two columns like
u_month between and u_empid between
May i know how can i write the query...
select U_empid,U_month,U_year,DocEntry from [@PR_OREIMCLM]
where U_empid between 843 and 846 and U_month between dec and apr
u_empid u_month u_year Docen
843
DEC
2013
1
827
FEB
2014
2
846
APR
2014
3Hi,
Could you try this,
select U_empid,U_month,U_year,DocEntry from [@PR_OREIMCLM]
where U_empid between 843 and 846 and
U_month in ('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
If U_month is datetime datatype, then we can use like
select U_empid,U_month,U_year,DocEntry from [@PR_OREIMCLM]
where U_empid between 843 and 846 and
substring(DATENAME(month,U_month),0,4) in ('Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')
or
select U_empid,U_month,U_year,DocEntry from [@PR_OREIMCLM]
where U_empid between 843 and 846 and
month(U_month) between 4 and 12
Hope this helps you...
Thanks & Regards,
Parvatha Solai.N -
Query Help:
http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
The above was my previous posting, which was not clear..so Iam restating my problem as follows....
I have the following tables
Customer(custID, Name, Address)
Order(custID, OrderID, orderDate)
CreditCard(custID, creditCard#, creditCardType)
Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
Order:
100,A001,11/22/03
100,A002,11/24/03
100,A003,12/02/03
CreditCard:
100,42323232..., VISA
100,5234234...., MASTER
Now how can I get
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
data in minimum no. of records....
I think I have made my query clear..
now please help me guys...
thanks so much for your help.You are right.
But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
Can you please help me with the query
if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
With the following fields in my query result,
custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
from Customer, Order, CreditCard tables
Thanks so much for your htlp -
Hi,
I am trying to call a procedure from a SQL report query. Please let me know if this is correct.
SELECT gb.period_name,
cc.segment1 uec,cc.segment2 dept, cc.segment3 other,
cc.segment4 acct,cc.segment5 subacct, cc.segment6 activity,
cc.segment7 cec, cc.segment8 subelement,cc.segment9 geo,
cc.segment10 usind,cc.segment11 affiliate,cc.segment12 mpc,
DECODE ( NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0),
0, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NULL, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0)
) AS Begining_balance_functional,
DECODE ( NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0),
0, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NULL, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)
) AS period_to_date_functional,
(DECODE ( NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0),
0, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NULL, ( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
NVL (gb.begin_balance_dr_beq, 0)
- NVL (gb.begin_balance_cr_beq, 0)
+ (DECODE ( NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0),
0, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NULL, ( NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0)
NVL (gb.period_net_dr_beq, 0)
- NVL (gb.period_net_cr_beq, 0)
) AS ending_balance_functional,
NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0) AS begining_balance_entered,
NVL (gb.period_net_dr, 0)
- NVL (gb.period_net_cr, 0) AS period_to_date_entered,
( NVL (gb.begin_balance_dr, 0)
- NVL (gb.begin_balance_cr, 0)
+ (NVL (gb.period_net_dr, 0) - NVL (gb.period_net_cr, 0)
) AS ending_balance_entered,
gb.currency_code,gb.period_year, gb.period_num,
apps.afl_gl_acct.get_value_description('ALCOA UEC',cc.segment1) UEC_Description, apps.afl_gl_acct.get_value_description('ALCOA Cost Center',cc.segment2) Cost_center_Description,
apps.afl_gl_acct.get_value_description('ALCOA Other',cc.segment3) Other_Description,
apps.afl_gl_acct.get_value_description('ALCOA Account',cc.segment4) Account_Description,
apps.afl_gl_acct.get_value_description('ALCOA SubAccount',cc.segment5) SubAccount_Description,
apps.afl_gl_acct.get_value_description('ALCOA Activity',cc.segment6) Activity_Description,
apps.afl_gl_acct.get_value_description('ALCOA CEC',cc.segment7) CEC_Description,
apps.afl_gl_acct.get_value_description('ALCOA SubElement',cc.segment8) SubElement_Description,
apps.afl_gl_acct.get_value_description('ALCOA GEO',cc.segment9) GEO_Description,
apps.afl_gl_acct.get_value_description('ALCOA US Ind',cc.segment10) US_Ind_Description,
apps.afl_gl_acct.get_value_description('ALCOA Affiliate',cc.segment11) Affil_Description,
afl_gl_acct.get_value_description('ALCOA MPC',cc.segment12) MPC_Description
FROM GL.GL_BALANCES GB, GL.GL_CODE_COMBINATIONS CC,
GL.GL_Budget_Versions GBV, GL.GL_SETS_OF_BOOKS GSB
WHERE GB.CODE_COMBINATION_ID = CC.CODE_COMBINATION_ID
-- And CC.SEGMENT1 = (se
And GB.BUDGET_VERSION_ID = GBV.BUDGET_VERSION_ID (+)
And GSB.SET_OF_BOOKS_ID = GB.SET_OF_BOOKS_ID
and decode(gb.TRANSLATED_FLAG,'Y','Translated','Entered') =:p_currency_type
AND cc.segment1 =:p_uec
AND GSB.NAME = :p_sob_name
AND gb.PERIOD_NAME= :p_period
AND cc.segment2= nvl(:p_dept,cc.segment2)
AND cc.segment3=nvl(:p_other,cc.segment3)
AND cc.segment4= nvl(:p_acct,cc.segment4)
AND cc.segment5= nvl(:p_subacct,cc.segment5)
AND cc.segment6 = nvl(:p_activity,cc.segment6)
AND cc.segment7 = nvl(:p_cec,cc.segment7)
and cc.segment8= nvl(:p_subelement,cc.segment8)
and cc.segment9= nvl(:p_geo,cc.segment9)
and cc.segment10=nvl(:p_usind,cc.segment10)
and cc.segment11=nvl(:p_affil,cc.segment11)
and cc.segment12=nvl(:p_mpc,cc.segment12)
AND gb.ACTUAL_FLAG = 'A'
AND gb.CURRENCY_CODE = :p_currency;
I am not completely sure of the syntax.
Regards,
JAPlease let me know if this is correct.Does it compile? Does it run? Does it return the correct result.
Please bear in mind we do not have access to your data models so we cannot run it. Nor do we know your business requirements so we cannot assess whether it implements them correctly. And it is way too big a hunk o' code for us to go through it manually.
As a rule of thumb it is better to build a small query and get that working correctly before adding tables to it rather than building an incomprehensibly large monolith.
Cheers, APC
Blog : http://radiofreetooting.blogspot.com/ -
My iPhone4s has been stolen,and it has been repaired in somewhere!Once the stealer had a new iPhone,I couldnot have my iPhone forever!what should I do?I am inChina,I have call police.But police seem to see it small.please help me,it has been my second lost iPhone4s
There is nothing to do. You have done all you can.
Buy a new iphone.
Buy a different phone.
Do without a phone. -
SQL Query Help - Is this possible or impossible????
Hi guys,
I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
For example,
I have 2 tables
The first table is:
1) COMPANY create table company (manufacturer varchar2(25),
date_established date,
location varchar2(25) );My sample test date is:
insert into company values ('Ford', 1902, 'USA');
insert into company values ('BMW', 1910, 'Germany');
insert into company values ('Tata', 1922, 'India');The second table is:
2) MODELS create table models (manufacturer varchar(25),
model varchar2(25),
price number(10),
year date,
current_production_status varchar2(1) ) ;My sample test data is:
insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
insert into models values ('Ford', 'Galaxy', 12000, 2008, 0);
insert into models values ('Ford', 'Escort', 10000, 1992, 1);
insert into models values ('BMW', '318', 17500, 2010, 0);
insert into models values ('BMW', '535d', 32000, 2006, 0);
insert into models values ('BMW', 'Z4', 10000, 1992, 0);
insert into models values ('Tata', 'Safari', 4000, 1999, 0);
insert into models values ('Tata', 'Sumo', 5500, 1996, 1);
insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer IN ('Ford', 'BMW', 'Tata')
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCWhat I want the query to output is this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0
Tata 1922 India Sumo 5500 1998 1If current_production_status is 1 it means this particular model has been discontinued
If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
So the query should output the one row where current_production_status is 1 for each manufacturer.
If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
My query as it is above will output all the records where current status is 1 or 0 like this
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
Tata 1922 India Sumo 5500 1998 1
Ford 1902 USA - - - 0
Ford 1902 USA - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
BMW 1910 Germany - - - 0
Tata 1922 India - - - 0
Tata 1922 India - - - 0However this is not what I want.
Any ideas how I can achieve the result I need?
Thanks!
P.S. Database version is '10.2.0.1.0'Hi Vishnu,
Karthiks query helped...
But this is the problem I am facing...
SELECT
com.manufacturer,
com.date_established,
com.location,
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
mod.current_production_status
FROM
company com,
models mod
WHERE
mod.manufacturer = com.manufacturer
and com.manufacturer = 'Ford'
and mod.current_production_status IN (1,0)
ORDER BY
mod.current_production_status DESCThe value of:
and com.manufacturer = 'Ford'will be dependent on front end user input....
When I run the query above I get all the rows where current_production_status is either 1 or 0.
I only require the rows where current_production_status is 1.
So if I amend it to look like this:
and mod.current_production_status = 1This works....
BUT if a user now passes in more than one manufacturer EG:
and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
So like this:
com.manufacturer com.date_established com.location mod.model mod.price mod.year mod.current_production_status
Ford 1902 USA Escort 10000 1992 1
BMW 1910 Germany - - - 0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
Thanks you so much!
This is really driving me insane :-( -
hii
i need a query help
i have two tables
the 1st table will look like this
associate id weekid no.of. hours
4000 810 40
4000 820 30
4000 830 60
4000 840 70
2nd table will look like this
associate id weekid no.of.hours
4000 810 40
4000 820 70
4000 830 130
4000 840 200
so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
for example
consider week id 830 and 840
in second table 830=130
840=200
when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
1 ---->>>> 840 - 830
=200 - 130
=70
in first table 840 has 70 hrs
like this it shud check with all records and it shud return only the records which are not equal
regards
srikanthThis..?
sql>select * from t1;
A_ID W_ID HRS
4000 810 40
4000 820 30
4000 830 60
4000 840 70
4000 850 80
sql>select * from t2;
A_ID W_ID HRS
4000 810 40
4000 820 70
4000 830 130
4000 840 200
4000 850 260
sql>
select a_id,w_id,hrs,sum_hrs
from(
select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
t2.hrs - nvl(lag(t2.hrs) over(order by t1.w_id),0) diff
from t1,t2
where t1.w_id = t2.w_id)
where diff != hrs;
A_ID W_ID HRS SUM_HRS
4000 850 80 260 -
Small query on methods of classes
Hi,
I have a small query abt calling methods in oops...How will we get the exporting,importing and exception parameters when we r calling the methods manually without the patterns options ????Well, the best way is of course to use the pattern, but you could also view the signature through SE24.
Transaction SE24
Enter class name, click display/change.
Click on methods tab.
Click your method.
Click the parameters button.
This will show you the signature of the method, including the importing, exporting, changing, and returning parameters.
Regards,
Rich Heilman -
I have iphone 4 screen goes small pleae help
i have iphone 4 m y screen resolution goes small pls help i cant do anything...
We need a clear, yet descriptive picture of what you are exeriencing. What is is you are seeting, and then what happends when the "problem" appears for you?
GB -
Hi all,
I have a variable type c and want to know whether it contains only numericals are not.
Lets say
test(5) type c.
test = '12345'.
if test co '0123456789'.
write : 'only numericals'.
elseIF NOT TEST = SPACE.
write : 'ALPHA numericals'.
ELSE.
write : 'SPACE'.
ENDIF.
tHIS WORKS FINE FOR INPUT 12345
SOMETIMES MY INPUT IS LIKE THIS
test = '345 '. OR test = ' 345'.
HERE THE OUTPUT SHOULD BE ONLY NUMERICALS.
IN ORDER TO ACHEIVE THIS I DID CHANGED THIS
if test co '0123456789'.
TO if test co '0123456789 '.: NOTE AFTER 9 I ADDED A SPACE
NOW IT WORKS FINE FOR THIS CODE .
THE ONLY PROBLEM WITH CODE IS
EVEN IF TEST = ' '.
IT GIVES ME A OUT PUT SAYING ONLY NUMERICALS
IN THIS CASE I WANT O/P AS SPACE
CAN ANYONE TELL ME HOW TO ACHEIVE THIS
THANKSHi preety .
Try in this way...
test(5) type c.
test = '12345'.
<b>if test co '0123456789 ' and test NE ' '.</b>
write : 'only numericals'.
ELSEif test = SPACE.
write : 'SPACE'.
elseIF NOT TEST = SPACE.
write : 'ALPHA numericals'.
else.
write : 'Other'.
endif.
ENDIF.
<b>Reward Points if it is helpful.</b>
Let me know if you need more help.
Thanks & Regards
ilesh 24x7 -
HUM ADG DYS (NIA, SIM, TRC, TRX) SMALL BRANDS (LUP, KAL,CRN,LPP,SYN)
MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI MON TUE WED THURS FRI
VENDOR
INT
QUAN
STER
LASH
OSP
HIB
PROD
I’d like to put together a query to populate the tables above,like count of recods for each vendor for each brand with the criteria for selecting within one week.
Here vendor_cd(INT,QUAN,STER,...etc),brand_cd(HUM,ADG,NIA,SIM,..eyc).we are extracting the details from file detail table whose column are like FILE_ID,FILE_RECEIPT_TS,REC_INSERT_TS,VENDOR_CD,BRAND_CD,RECORD_COUNT.
Edited by: ASHWINI89 on Mar 21, 2013 8:33 PMWelcome to the forum!!
Please consider the following when you post a question. This would help us help you better
1. New features keep coming in every oracle version so please provide Your Oracle DB Version to get the best possible answer.
You can use the following query and do a copy past of the output.
select * from v$version 2. This forum has a very good Search Feature. Please use that before posting your question. Because for most of the questions
that are asked the answer is already there.
3. We dont know your DB structure or How your Data is. So you need to let us know. The best way would be to give some sample data like this.
I have the following table called sales
with sales
as
select 1 sales_id, 1 prod_id, 1001 inv_num, 120 qty from dual
union all
select 2 sales_id, 1 prod_id, 1002 inv_num, 25 qty from dual
select *
from sales 4. Rather than telling what you want in words its more easier when you give your expected output.
For example in the above sales table, I want to know the total quantity and number of invoice for each product.
The output should look like this
Prod_id sum_qty count_inv
1 145 2 5. When ever you get an error message post the entire error message. With the Error Number, The message and the Line number.
6. Next thing is a very important thing to remember. Please post only well formatted code. Unformatted code is very hard to read.
Your code format gets lost when you post it in the Oracle Forum. So in order to preserve it you need to
use the {noformat}{noformat} tags.
The usage of the tag is like this.
<place your code here>\
7. If you are posting a *Performance Related Question*. Please read
{thread:id=501834} and {thread:id=863295}.
Following those guide will be very helpful.
8. Please keep in mind that this is a public forum. Here No question is URGENT.
So use of words like *URGENT* or *ASAP* (As Soon As Possible) are considered to be rude. -
Query help on Goods Receipt Query with AP Invoice
Looking for a little help on a query. I would like to list all the goods receipts for a given date range and then display the AP Invoice information (if its been copied to an AP Invoice). I think my problem is in my where clause, I plagerized an SAP query to show GR and AP from a PO as a start. SBO 2005 SP01. Any help would be great appreciated. Thanks
SELECT distinct 'GR',
D0.DocStatus,
D0.DocNum ,
D0.DocDate,
D0.DocDueDate,
D0.DocTotal,
'AP',
I0.DocStatus,
I0.DocNum ,
I0.DocDate,
I0.DocDueDate,
I0.DocTotal,
I0.PaidToDate
FROM
((OPDN D0 inner Join PDN1 D1 on D0.DocEntry = D1.DocEntry)
full outer join
(OPCH I0 inner join PCH1 I1 on I0.DocEntry = I1.DocEntry)
on (I1.BaseType=20 AND D1.DocEntry = I1.BaseEntry AND D1.LineNum=I1.BaseLine))
WHERE
(D1.BaseType=22 AND D1.DocDate>='[%0]' AND D1.DocDate<='[%1]')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry
FROM PDN1 WHERE BaseType=22 AND DocDate>='[%0]' AND DocDate<='[%1]'))Hi Dalen ,
I believe it is because of the condition
(D1.BaseType=22 AND D1.DocDate>='%0' AND D1.DocDate<='%1')
OR (I1.BaseType=20 AND I1.BaseEntry IN
(SELECT Distinct DocEntry FROM PDN1 WHERE PDN1.BaseType=22 AND DocDate>='%0' AND DocDate<='%1'))
Try changing
D1.BaseType=22 OR D1.DocDate>='%0' AND D1.DocDate<='%1
PDN1.BaseType=22 OR DocDate>='%0' AND DocDate<='%1'))
Lets see what would be the result . Lets have some fun with troubleshooting
See what would be the difference in the result .
Thank you
Bishal -
Query help: query to return column that represents multiple rows
I have a table with a name and location column. The same name can occur multiple times with any arbitrary location, i.e. duplicates are allowed.
I need a query to find all names that occur in both of two separate locations.
For example,
bob usa
bob mexico
dot mexico
dot europe
hal usa
hal europe
sal usa
sal mexico
The query in question, if given the locations usa and mexico, would return bob and sal.
Thanks for any help or advice,
-=beekyHow about this?
SELECT NAME
FROM <LOCATIONS_TABLE>
WHERE LOCATION IN ('usa','mexico')
GROUP BY NAME
HAVING COUNT(DISTINCT LOCATION) >= 2Results:
SQL> WITH person_locations AS
2 (
3 SELECT 'bob' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
4 SELECT 'bob' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
5 SELECT 'dot' AS NAME, 'Mexico' AS LOCATION FROM DUAL UNION ALL
6 SELECT 'dot' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
7 SELECT 'hal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
8 SELECT 'hal' AS NAME, 'Europe' AS LOCATION FROM DUAL UNION ALL
9 SELECT 'sal' AS NAME, 'USA' AS LOCATION FROM DUAL UNION ALL
10 SELECT 'sal' AS NAME, 'Mexico' AS LOCATION FROM DUAL
11 )
12 SELECT NAME
13 FROM person_locations
14 WHERE LOCATION IN ('USA','Mexico')
15 GROUP BY NAME
16 HAVING COUNT(DISTINCT LOCATION) >= 2
17 /
NAM
bob
salHTH!
Edited by: Centinul on Oct 15, 2009 2:25 PM
Added sample results. -
QUERY HELP!!! trying to create a query
i'm creating a summary report
i have a table with sale dates
for example i have a table tab_1 and column saleDate as
saleDat
1923
1936
1945
2003
2005
saleDate contains years and there are some missing years where no sale
was made
My report has to display years starting from earliest year
so i have to create a query that starts with 1923
but the problem is that I have to have years that are not in table.
for example i have to display years 1924 which is not in table
so the part of report has to look like
1923 blah blah summary.........
1924 "
1925
1926
2005
2006
upto current year (2006 may not be in the table, but i have to display)
i just need to know the query that can query all the years starting from
the ealiest saleDate to current year
thanks in advancePlease write the query in the following form:
SELECT a.year, --- place other columns from your table.
FROM (SELECT (:start_num + rownum) year
FROM all_tab_columns
WHERE :start_num + rownum <= :end_num) a,
tab_1 b
WHERE a.year = b.saleDat(+);
Note:
1) if your start year and end year are 1923 and 2006. Then input as below:
:start_num = 1922
:end_num = 2006
2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
Hope this helps.
- Saumen. -
Pulling open invoices, and paid invoices with details (Query Help).
Hello All,
I am sure I messed something up in my joins. I am looking to pull a report of all invoices OINV for a month, then list details of any payment (if it is paid) next to it from RCT2. It is giving me a list of all of the paid invoices, but even though I have a LEFT JOIN it is not listing any of the invoices without payments.
This is where I am now from the report wizard in Crystal.
SELECT "OINV"."DocNum", "OINV"."SlpCode", "OINV"."CardCode", "OINV"."DocTotal", "OINV"."U_Commission", "OSLP"."SlpName", "RCT2"."DcntSum", "ORCT"."TaxDate", "OINV"."DocEntry", "OINV"."TotalExpns", "OINV"."CANCELED", "ORCT"."Canceled", "ORCT"."DocNum", "RCT2"."InvType"
FROM ("DBName"."dbo"."OINV" "OINV" LEFT OUTER JOIN "DBName"."dbo"."OSLP" "OSLP" ON "OINV"."SlpCode"="OSLP"."SlpCode")
INNER JOIN ("DBName"."dbo"."ORCT" "ORCT" INNER JOIN "DBName"."dbo"."RCT2" "RCT2" ON "ORCT"."DocNum"="RCT2"."DocNum")
ON "OINV"."DocEntry"="RCT2"."DocEntry"
WHERE "OINV"."CANCELED"='N' AND "ORCT"."Canceled"='N' AND "RCT2"."InvType"<=N'14'
ORDER BY "OINV"."SlpCode", "ORCT"."DocNum", "ORCT"."TaxDate"
Thank you in advance for any help you can give me.Hello Kiran,
I thought about that, but my purposes for running the report is to determine commission based on the date that the invoice was paid, I need the TaxDate in ORCT as it relates to the payment in RCT2.
Removing the ORCT.cancelled condition and the RCT2.invtype conditions now pulls all of the invoices, paid and unpaid. I know now I cant have them in my query, when the record does not exist in ORCT it doesnt have a value for cancelled, and when there is no record in RCT2 there is no invtype, and is filtered.
Maybe I can say where ORCT.Canelled = 'N' OR ORCT.Cancelled = NULL, but I dont know if that would work.
Maybe you are looking for
-
I have erased my hard drive, and now i cant find it on DU
I have erased my hard drive, now when i'm trying to re-install mountain lion i can't see the hard drive in DU. Any ideas on how to restore this?
-
Flashback transaction query output
Hi there, Here is my small demo. C:\Documents and Settings\Aman>net start oracleserviceorcl The OracleServiceORCL service is starting............................. The OracleServiceORCL service was started successfully. C:\Documents and Settings\Aman>
-
Incrementing the Xmx option to launch a JVM
I'm developing an application launcher (creating an exe using JNI from C++) to launch a Java application. As it is a memory extensive app I need to have 1G of maximum heap space. I'm setting the JavaVMOption -Xmx1024M but is going to fail to allocate
-
Does 'Oracle Standard Editon One' offering come with Location ? Spatial ? Thank you for your information
-
UJBR transaction data restore shows no data
Dear All, We did a transaction data backup on the PROD to restore in QA. The UJBR restoration of transaction data on QA shows as successful both in foreground and background modes. However, no data is seen on the models. When i checked the zipped fil