SQL query: select billaddress if no delivery address exist.
hi sql expert,
The Query shall filter all invoices by date, articles and show the delivery address. Problem: Not every customer has deposited a delivery address. In this case the billing address is to be taken.
How can this be done ?
This query
SELECT T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity] FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
and T1.Itemcode = [%0] GROUP BY T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
UNION ALL
SELECT T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], -T1.[Price], -(T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt], ('-' + substring(T1.Freetxt,0,5)) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", -T1.[Quantity] FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]' and T1.Itemcode = [%0]
GROUP BY T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
Thanks a lot!
hi,
I think I got it now :-)
First: Show me priority all delivery addresses . Otherwise billing addresses:
SELECT T1.[CardCode], T2.[Street] FROM OCRD T1 INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode WHERE NOT EXISTS
SELECT *
FROM CRD1 as T2
WHERE T2.[AdresType] = 's' and t1.CardCode = t2.Cardcode
union
SELECT T1.[CardCode], T2.[Street] FROM OCRD T1 INNER JOIN CRD1 T2 ON T1.CardCode = T2.CardCode
where T2.[AdresType] = 's'
secondly:
Filter all invoices by date, articles and show priority the delivery address else billingaddress and subtract the credits:
SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
and T1.Itemcode = [%0] and not exists (
SELECT *
FROM CRD1 as T3
WHERE T3.[AdresType] = 's' and t2.CardCode = t3.Cardcode
GROUP BY T0.[Cardcode], T0.[DocNum],T0.[CardCode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
union
SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
Where T3.[AdresType] = 's' and T1.Itemcode = [%0] and CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
-- ab hier werden die Gutschriften abgezogen
union
SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], -T1.[Price], -(T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt], ('-' + substring(T1.Freetxt,0,5)) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", -T1.[Quantity] FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode WHERE CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]' and T1.Itemcode = [%0]
and not exists (
SELECT *
FROM CRD1 as T3
WHERE T3.[AdresType] = 's' and t2.CardCode = t3.Cardcode
GROUP BY T0.[Cardcode], T0.[DocNum], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], T1.[FreeTxt], T1.[Quantity]
union
SELECT T0.[Cardcode], T0.[CardName], T3.[ZipCode],T3.[Street], T1.[ItemCode], T1.[Dscription], T1.[ShipDate], T1.[Price], (T1.[Price] * T1.[Quantity]) as "Gesamtpreis in €", T1.[FreeTxt],substring(T1.Freetxt,0,5) as "Grundpreis in €",substring(T1.Freetxt,9,6) as "TS-Wert in %", T1.[Quantity]
FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OCRD T2 ON T0.CardCode = T2.CardCode INNER JOIN CRD1 T3 ON T2.CardCode = T3.CardCode
Where T3.[AdresType] = 's' and T1.Itemcode = [%0] and CONVERT(nvarchar(8), T1.ShipDate, 112) BETWEEN '[%FromDate]' AND '[%ToDate]'
Similar Messages
-
[SQL QUERY] Select TCP Port Monitors and their related Watcher Node
Hi everybody,
I'm working on a SSRS report and SQL Query, I have no problem to find all my TCP Port Monitor (SCOM 2012 R2) based on the DisplayName, but I can't figure out how to get their related watcher nodes (in my case only 1 computer is a watcher node).
I can't find which table, which field, contains this information..?
Here is the query i started to write (i select * since i still searching for the right column):
SELECT
FROM StateView s
INNER JOIN BaseManagedEntity me on me.BaseManagedEntityId=s.BaseManagedEntityId
INNER JOIN MonitorView mv on mv.Id=s.MonitorId
INNER JOIN ManagedTypeView mtv on mtv.Id=s.TargetManagedEntityType
--where mv.DisplayName like 'Ping Target Status Check%'
AND me.IsDeleted = '0'
where mv.DisplayName like '%tcpmon%'
and mv.LanguageCode = 'ENU'
--and s.HealthState in (@state)
ORDER BY s.Lastmodified DESC
It would be great if someone can help me !
Thanks,
JulienHi,
After creating a TCP port monitor, we can find a table for this monitor under operationsmanager database :
SELECT *
FROM [OperationsManager].[dbo].[MT_TCPPortCheck_******WatcherComputersGroup]
You will find the warcher computer group.
Regards,
Yan Li
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected] -
Sql query - Selecting last recorded values for each date in specified period
Hello,
Can someone please help me with my problem.
I'm trying to get last recorded balance for each day for specific box (1 or 2) in specified period of days from ms access database using ADOTool.
I'm trying to get that information with SQL query but so far unsuccessfully...
My table looks like this:
Table name: TestTable
Date Time Location Box Balance
20.10.2014. 06:00:00 1 1 345
20.10.2014. 12:00:00 1 1 7356
20.10.2014. 18:45:00 1 1 5678
20.10.2014. 23:54:00 1 1 9845
20.10.2014. 06:00:02 1 2 35
20.10.2014. 12:00:04 1 2 756
20.10.2014. 18:45:06 1 2 578
20.10.2014. 23:54:10 1 2 845
21.10.2014. 06:00:00 1 1 34
21.10.2014. 12:05:03 1 1 5789
21.10.2014. 15:00:34 1 1 1237
21.10.2014. 06:00:00 1 2 374
21.10.2014. 12:05:03 1 2 54789
21.10.2014. 15:00:34 1 2 13237
22.10.2014. 06:00:00 1 1 8562
22.10.2014. 10:00:00 1 1 1234
22.10.2014. 17:03:45 1 1 3415
22.10.2014. 22:00:00 1 1 6742
22.10.2014. 06:00:05 1 2 562
22.10.2014. 10:00:16 1 2 123
22.10.2014. 17:03:50 1 2 415
22.10.2014. 22:00:10 1 2 642
23.10.2014. 06:00:00 1 1 9876
23.10.2014. 09:13:00 1 1 223
23.10.2014. 13:50:17 1 1 7768
23.10.2014. 19:47:40 1 1 3456
23.10.2014. 21:30:00 1 1 789
23.10.2014. 23:57:12 1 1 25
23.10.2014. 06:00:07 1 2 976
23.10.2014. 09:13:45 1 2 223
23.10.2014. 13:50:40 1 2 78
23.10.2014. 19:47:55 1 2 346
23.10.2014. 21:30:03 1 2 89
23.10.2014. 23:57:18 1 2 25
24.10.2014. 06:00:55 1 1 346
24.10.2014. 12:30:22 1 1 8329
24.10.2014. 23:50:19 1 1 2225
24.10.2014. 06:01:00 1 2 3546
24.10.2014. 12:30:26 1 2 89
24.10.2014. 23:51:10 1 2 25
Let's say the period is 21.10.2014. - 23.10.2014. and I want to get last recorded balance for box 1. for each day. The result should look like this:
Date Time Location Box Balance
21.10.2014. 15:00:34 1 1 1237
22.10.2014. 22:00:00 1 1 6742
23.10.2014. 23:57:12 1 1 25
So far I've managed to write a query that gives me balance for ONLY ONE date (date with highest time in whole table), but I need balance for EVERY date in specific period.
My incorrect code (didn't manage to implement "BETWEEN" for dates...):
SELECT TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM TestTable
WHERE Time=(SELECT MAX(Time)
FROM TestTable
WHERE Location=1 AND Box=1 );
Tnx!
Solved!
Go to Solution.For loop
following query keep day (here 24 in below query) Variable from ( 1 to 28-29/30/31 as per month)
SELECT TOP 1 TestTable.[Date], TestTable.[Time], TestTable.[Location], TestTable.[Box], TestTable.[Balance]
FROM Test Table.
WHERE Time=(SELECT MAX(Time) FROM TestTable WHERE Location=1 AND Box=1 )
AND DATE = "2014-10-24";
PBP (CLAD)
Labview 6.1 - 2014
KUDOS ARE WELCOMED.
If your problem get solved then mark as solution. -
SQL query using not equal to or not exists
Hi All;
From the below table , i need to display the client name
where output is not equal to Pre Start, BA
but display client with output only with SOSP
so only in the below example DEF client name will be displayed
below is my query
select C.new_applicationformid,
C.clientname ,
C.new_noofappointments
From (
Select A.new_applicationformid ,A.new_programmecontractidname,Count(1) As Cnt
from FilteredNew_applicationform as a
full outer join filteredNew_Evidence as aa on (a.new_applicationformid = aa.new_relatedapplicationid)
Group By A.new_applicationformid ,A.new_programmecontractidname
Having Count(1) >= 1) A
Inner Join filteredNew_Evidence AA on a.new_applicationformid = aa.new_relatedapplicationid
Inner Join FilteredNew_applicationform C on C.new_applicationformid = aa.new_relatedapplicationid
Where ((aa.output in ('SOSP'))
and (aa.output not in ('Pre Start','BA') )
Any help much appreciated
Thanks
Pradnya07See examples written by Joe Celko to help you out
CREATE TABLE PilotSkills
(pilot CHAR(15) NOT NULL,
plane CHAR(15) NOT NULL,
PRIMARY KEY (pilot, plane));
PilotSkills
pilot plane
=========================
'Celko' 'Piper Cub'
'Higgins' 'B-52 Bomber'
'Higgins' 'F-14 Fighter'
'Higgins' 'Piper Cub'
'Jones' 'B-52 Bomber'
'Jones' 'F-14 Fighter'
'Smith' 'B-1 Bomber'
'Smith' 'B-52 Bomber'
'Smith' 'F-14 Fighter'
'Wilson' 'B-1 Bomber'
'Wilson' 'B-52 Bomber'
'Wilson' 'F-14 Fighter'
'Wilson' 'F-17 Fighter'
CREATE TABLE Hangar
(plane CHAR(15) NOT NULL PRIMARY KEY);
Hangar
plane
=============
'B-1 Bomber'
'B-52 Bomber'
'F-14 Fighter'
PilotSkills DIVIDED BY Hangar
pilot
=============================
'Smith'
'Wilson'
SELECT DISTINCT pilot
FROM PilotSkills AS PS1
WHERE NOT EXISTS
(SELECT *
FROM Hangar
WHERE NOT EXISTS
(SELECT *
FROM PilotSkills AS PS2
WHERE (PS1.pilot = PS2.pilot)
AND (PS2.plane = Hangar.plane)));
SELECT PS1.pilot
FROM PilotSkills AS PS1, Hangar AS H1
WHERE PS1.plane = H1.plane
GROUP BY PS1.pilot
HAVING COUNT(PS1.plane) = (SELECT COUNT(plane) FROM Hangar);
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 -
How to run a sql query (select) in parallel
Hi All,
I would like to do a select using the 8 cpus our production
server has. My select is simple in just one table but its a big
table (aprox. 10.000.000 rows) and I have to do a full scan in
it. I know oracle does that, but how? do I put a clause in the
select telling oracle to do the query in parallel? Has anyone
done that, yet?
Tks,
Marcelo Lopes
Rio de Janeiro - Brazil
It's a hot sunny day today :)You could either include a parallel clause in the table
definition or alter the tble to include parallelism, or put a hint
on the SQL ..
alter table my_table parallel (degree 16);
or
select /*+ parallel(my_table, 16) */ ... -
Hello Colleague,
I have a table that contains multiple entries of TABLE NAME.
I need to query the databse table and check if certain entry exist in that table.
I Loop over the table containing the tablenames and try a select :
Loop at lt_key into ls_key.
SELECT * FROM (ls_key) WHERE field = 'ABC' .
ENDLOOP.
It gives me a error and asks to store the result using INTO. Now i am confused with the type of result because the tablename is provided dynamically.
Could you please help.
Thanks in advance.
PiyushHI,
I did something similar to it, the following program accepts table
name and fields from user and sort dynamically.
REPORT zreport_SORT.
parameters:
p_f1(15) obligatory,
p_f2(15) obligatory,
p_f3(15) obligatory,
p_table(15).
data:
w_tab type ref to data,
fs_tab type ref to data,
w_flag,
w_count type i.
create data w_tab type table of (p_table) .
create data fs_tab type (p_table).
data:
t_tab type table of spfli,
fs_tab1 like line of t_tab.
field-symbols:
<fs> type any table,
<fs1> type any,
<fs2> type any,
<fs3> type any,
<fs4> type any.
at selection-screen.
select count(*)
from dd03l
into w_count
where tabname eq p_table
and fieldname eq p_f1.
if w_count eq 0.
w_flag = 'Y'.
endif.
select count(*)
from dd03l
into w_count
where tabname eq p_table
and fieldname eq p_f2.
if w_count eq 0.
w_flag = 'Y'.
endif.
select count(*)
from dd03l
into w_count
where tabname eq p_table
and fieldname eq p_f3.
if w_count eq 0.
w_flag = 'Y'.
endif.
if w_flag eq 'Y'.
clear w_flag.
Message 'Incorrect field name' type 'E'.
endif.
start-of-selection.
assign w_tab->* to <fs>.
assign fs_tab->* to <fs1>.
select *
from (p_table)
into corresponding fields of
table <fs> up to 10 rows.
sort <fs> by (p_f1) ascending (p_f2) ascending (p_f3) ascending.
assign component p_f1 of structure <fs1> to <fs2>.
assign component p_f2 of structure <fs1> to <fs3>.
assign component p_f3 of structure <fs1> to <fs4>.
loop at <fs> into <fs1>.
write:/ <fs2>,
<fs3>,
<fs4>.
endloop.
Regards and Best wishes. -
ABAP SQL Query (Select data from intervals)
Hi All,
From To Temp
101 200 1111
201 300 2222
301 400 3333
401 500 4444
501 600 5555
From, To & Temp are three Fields.
Consider the above table, if i enter input as 150, need to pick 1111.
If the input is inbetween of From & To values means I want to pick the exact
Data from temp field.
Thanks
Hema
Edited by: hema prabakaran on Jan 19, 2009 7:54 AM
Edited by: hema prabakaran on Jan 19, 2009 8:30 AMHi
Data: itab type table of tbl with header line.
select * from tbl into table itab.
if sy-subrc eq 4.
Message E000(YJK).
else.
loop at itab.
if v_temp between itab-from and itab-to.
write itab-temp.
exit.
else.
continue.
endif.
endloop.
endif.
You can use the above code.
It is not possible to use select stmt with your i/p variable in the where clause as that field is not present in table.
hope this helps
Regards,
Jayanthi.K -
SQL query - select one row from each date group
Hi,
I have data as follows.
Visit_Date Visit_type Consultant
05/09/2009 G name1
05/09/2009 G name2
05/09/2009 G name3
06/09/2009 I name4
07/09/2009 G name5
07/09/2009 G name6
How to select data as follows
05/09/2009 G name1
06/09/2009 G name4
07/09/2009 G name5
i.e one row from every visit_date
Thanks,
MK Nathan
Edited by: k_murali on Oct 7, 2009 10:44 PMAre you after this (one row per date per visit_type)
with dd as (select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name1' Consultant from dual
union all
select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name2' Consultant from dual
union all
select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name3' Consultant from dual
union all
select to_date('06/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name4' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name5' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name6' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'F' Visit_type, 'name7' Consultant from dual)
select trunc(visit_date) visit_date, visit_type, min(consultant)
from dd
group by trunc(visit_date), visit_type
order by trunc(visit_date);
VISIT_DAT V MIN(C
09/MAY/09 G name1
09/JUN/09 G name4
09/JUL/09 G name5
09/JUL/09 F name7or are you after only one row per date?:
with dd as (select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name1' Consultant from dual
union all
select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name2' Consultant from dual
union all
select to_date('05/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name3' Consultant from dual
union all
select to_date('06/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name4' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name5' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'G' Visit_type, 'name6' Consultant from dual
union all
select to_date('07/09/2009','MM/DD/YYYY') Visit_Date, 'F' Visit_type, 'name7' Consultant from dual)
select trunc(visit_date) visit_date, min(visit_type) visit_type, min(consultant)
from dd
group by trunc(visit_date)
order by trunc(visit_date);
VISIT_DAT V MIN(C
09/MAY/09 G name1
09/JUN/09 G name4
09/JUL/09 F name5 -
Sql query-filter if 1 set of data exists and in the same time 2 set doesnt
Hi guys,
I need to write a query where I filter on certain data being present, but in the same time other data from the same table being not present.
For example:
ProceduresTable:
Type 1
Type 1
Type 2
Type 2
Type 1
MyTable:
Name
OtherFields
JoiningTable (many to many)
ProceduresTable_Key
MyTable_Key
I need to select all records from MyTable and Procedures for which there are procedures from Type 1 but there are no procedures from Type 2 in the same time.
So far I've been only able to do that by using subqueries and I think there should be an easier way to do that.
Here is what I have:
Select * From MyTable, Procedures, JoiningTable Where JOINING_CONDITIONS AND Type = 1 AND NAME_SOME_COLUMN NOT IN (SELECT NAME_SOME_COLUMN FROM ... WHERE Type = 2 and inner.Name = outer.Name)
Hope you understand my meta code. I have Oracle 9 db.
Thanks a lot!Hi,
Welcome to the forum!
Whenever you have a question, it helps if you post a specific example. Include CREATE TABLE and INSERT statements for a little sample data, and also post the results you want from that data.
if you can use commonly available tables (like those in the scott or hr schemas) to illustrate your proble, then you don't have to post the sample data; just the results.
For example, I think you're asking something like this:
"How can I find information about people in the sciott.emp table who are in a department that has at least one CLERK ( that is, a row with job='CLERK') but no SALESMAN? That is, I want these results:
{code}
ENAME DEPTNO JOB
CLARK 10 MANAGER
KING 10 PRESIDENT
MILLER 10 CLERK
JONES 20 MANAGER
FORD 20 ANALYST
ADAMS 20 CLERK
SMITH 20 CLERK
SCOTT 20 ANALYST
{code}
One way is to use CASE expressions instead of WHERE clauses to test for the criteria, then using the reults of the CASE expressions in the WHERE clause.
For example:
WITH got_cnts AS
SELECT ename, deptno, job
, COUNT ( CASE
WHEN job = 'CLERK'
THEN 1
END
) OVER (PARTITION BY deptno) AS clerk_cnt
, COUNT ( CASE
WHEN job = 'SALESMAN'
THEN 1
END
) OVER (PARTITION BY deptno) AS salesman_cnt
FROM scott.emp
SELECT ename, deptno, job
FROM got_cnts
WHERE clerk_cnt > 0
AND salesman_cnt = 0
;The problem here is that you can't always tell, by looking at any one row, if it should be included or not; in this case, you need to know something about the department as a whole. Analytic functions can look at the department as a whole, but analytic functions are computed after the WHERE clause is applied, so to use the results of the analytic functions in a WHERE clause, we need to do the analytics first, in a sub-query, and the WHERE clause later.
Sometimes (as in the example above) analytic functions are useful; other times, aggregate functions are more appropriate, depending on the exact requirements.
Edited by: Frank Kulash on Apr 12, 2010 9:00 AM -
Form on a SQL Query - doesn't work with SELECT * - bug or feature ?
When I do this,
Create Page -> Page with Component -> Form -> Form on a SQL Query -> SELECT * FROM EMP
I do not get any items displayed and it creates a simple HTML region / page. Do we have to necessarily specify the column names ?
Iam looking at a way to see if any addition of columns in the table does not involve IT intervention in recreating the form.
When we try to create with Form on a SQL Query, then shouldn't it be similar to the Report where the same thing works, if I give SELECT function_returning_columns() from DUAL even then the same thing happens where it creates an ITEM called functions_returning_columns() it creates HTML region
I asked a related question with no answer :-( in
Dynamic Creation of Items in Runtime through Application UIHi Marc,
Thanks. I just tried something like this. Taking the EMP table example, (it doesn't matter which table), I created a region based on a Pl/Sql function returning SQL query
( I selected the vertical report template including nulls to display it like a form ) :
DECLARE
v_sql VARCHAR2(3000) ;
mn_idx NUMBER := 1 ;
BEGIN
v_sql := 'SELECT ' ;
FOR recs IN (SELECT * FROM ALL_TAB_COLUMNS WHERE TABLE_NAME = 'EMP' ORDER BY COLUMN_ID)
LOOP
v_sql := v_sql || 'HTMLDB_ITEM.TEXT(' || mn_idx || ',' ||
recs.column_name || ') ' || recs.column_name || ', ' ;
mn_idx := mn_idx + 1 ;
END LOOP ;
v_sql := SUBSTR(v_sql, 1, LENGTH(v_sql) -2) ;
v_sql := v_sql || ' FROM EMP WHERE EMPNO = 7369 ORDER BY 1 ' ;
RETURN v_sql ;
END ;
This allowed me to do my updates etc.., Then I created a button called 'Apply' and a process called 'update_changes' on button click and defined this:
DECLARE
v_sql varchar2(1000) ;
mn_ctr NUMBER := 1 ;
BEGIN
v_sql := 'BEGIN UPDATE EMP SET ' ;
FOR recs IN (select COLUMN_ID, COLUMN_NAME, DATA_TYPE
from all_tab_columns where table_name = 'EMP'
ORDER BY COLUMN_ID) loop
-- Make changes here if required- this is assuming 9 columns --
v_sql := v_sql || recs.column_name || ' = HTMLDB_APPLICATION.G_F0' || mn_ctr || '(1),' ;
mn_ctr := mn_ctr + 1;
end loop ;
v_sql := substr(v_sql, 1, length(v_sql) - 1) ;
v_sql := v_sql || ' WHERE EMPNO = 7369; END ;' ;
execute immediate (v_sql) ;
END ;
Since this is for example, I didn't include code for Checksum and hardcoded empno = condition and have provision for 9 columns. I made some changes and tried saving it and I was able to do it.
I altered the table to add a column / drop a column and when I relogin, Iam able to see the changes.
Can you tell me if there could be any drawbacks in this approach ?. -
T-SQL query performance (CLR func + webservice)
Hi guys
I have CLR function which accepts address as a parameter, calls geocoding webservice and returns some information (coordinates etc.)
I run SQL query
SELECT *FROM T CROSS APPLY CLR_Func(T.Address)F
Table contains 8 million records and obviously query runs very slow.
Do you know any nice way to improve performance in this situation?
Thank you,
MaxNo WHERE condition? SQL Server will call the function 8 million times ....
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 -
I am trying to execute the following SQl query, SELECT * FROM Failure WHERE ID = '123' AND RepairAction = ' ';, using the DB Tools Execute Query.vi. This query never finds the record in my database. My database contains a record where the ID filed contains the value of '123' and the RepairAction field is an empty string. If I remove the 'AND RepairAction ' ';' text from my query statement, the record is found. I believe my problem is that I am not using the correct syntax to describe and empty string. I have tried the following: '', ' ', "", " ", and NULL as empty string arguments, and none of these work.
I was hoping someone might be able to tell me what the correct syntax is for an empty string or if there is another approach I need to take.
Thank you in advance for your help,
Jim
Solved!
Go to Solution.Hi,
While creating your table "Failure", was the column "ID" delclared as intiger or varchar? If it is intiger and you use '123' , it wont return the results. You will have to try without the inverted comas ' '.
Regards,
Nitzz
(Giver Kudos to good Answers, Mark it as a solution if your problem is Solved) -
SQL Query for TOP 10 Average CPU
Have a SCOM Report request for a line graph showing top 10 average CPU for a group of servers. I have a query that will show all of the servers in a group for the last day, with the average CPU by hour. How can I extend the SQL query to only select the TOP
10 average CPU from the group? Here is the Query I have:
SELECT
vPerf.DateTime,
vPerf.SampleCount,
cast(vPerf.AverageValue as numeric(10,2)) as AverageCPU,
vPerformanceRuleInstance.InstanceName,
vManagedEntity.Path,
vPerformanceRule.ObjectName,
vPerformanceRule.CounterName
FROM Perf.vPerfHourly AS vPerf INNER JOIN
vPerformanceRuleInstance ON vPerformanceRuleInstance.PerformanceRuleInstanceRowId = vPerf.PerformanceRuleInstanceRowId INNER JOIN
vManagedEntity ON vPerf.ManagedEntityRowId = vManagedEntity.ManagedEntityRowId INNER JOIN
vPerformanceRule ON vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId
WHERE
vPerf.DateTime >= DATEADD(Day, -1, GetDate())
AND vPerformanceRule.ObjectName like '%Processor Information%'
AND vPerformanceRuleInstance.InstanceName = '_Total'
AND (vPerformanceRule.CounterName IN ('% Processor Time'))
AND (vManagedEntity.Path IN (SELECT dbo.vManagedEntity.Name
FROM dbo.vManagedEntity INNER JOIN
dbo.vRelationship On dbo.vManagedEntity.ManagedEntityRowId = dbo.vRelationship.TargetManagedEntityRowId INNER JOIN
dbo.vManagedEntity As CompGroup On dbo.vRelationship.SourcemanagedEntityRowId = CompGroup.ManagedEntityRowId
WHERE CompGroup.DisplayName = 'bemis ibb prod'
ORDER BY path, vPerf.DateTime
Results
DateTime
SampleCount
AverageCPU
InstanceName
Path
ObjectName
CounterName
2/26/15 3:00 PM
2
1.98
_Total
servername.corp.com
Processor Information
% Processor Time
2/26/15 4:00 PM
2
2.09
_Total
servername.corp.com
Processor Information
% Processor Time
2/26/15 5:00 PM
2
1.72
_Total
servername.corp.com
Processor Information
% Processor Time
2/26/15 6:00 PM
2
1.83
_Total
servername.corp.com
Processor Information
% Processor Time
Thanks in Advance!
Mike HanlonHi
Sql Query
SELECT TOP 10
vPerf.DateTime,
vPerf.SampleCount,
cast(vPerf.AverageValue as numeric(10,2)) as AverageCPU,
vPerformanceRuleInstance.InstanceName,
vManagedEntity.Path,
vPerformanceRule.ObjectName,
vPerformanceRule.CounterName
FROM Perf.vPerfHourly AS vPerf INNER JOIN
vPerformanceRuleInstance ON vPerformanceRuleInstance.PerformanceRuleInstanceRowId = vPerf.PerformanceRuleInstanceRowId
INNER JOIN
vManagedEntity ON vPerf.ManagedEntityRowId = vManagedEntity.ManagedEntityRowId INNER JOIN
vPerformanceRule ON vPerformanceRuleInstance.RuleRowId = vPerformanceRule.RuleRowId
WHERE
vPerf.DateTime >= DATEADD(Day, -1, GetDate())
AND vPerformanceRule.ObjectName like '%Processor Information%'
AND vPerformanceRuleInstance.InstanceName = '_Total'
AND (vPerformanceRule.CounterName IN ('% Processor Time'))
AND (vManagedEntity.Path IN (SELECT dbo.vManagedEntity.Name
FROM dbo.vManagedEntity INNER JOIN
dbo.vRelationship On dbo.vManagedEntity.ManagedEntityRowId = dbo.vRelationship.TargetManagedEntityRowId INNER
JOIN
dbo.vManagedEntity As CompGroup On dbo.vRelationship.SourcemanagedEntityRowId = CompGroup.ManagedEntityRowId
WHERE CompGroup.DisplayName = 'bemis ibb prod'
ORDER BY path, vPerf.DateTime
Regards
sridhar v -
Help with sql query the status of A/P Reserve Invoice
Hi,
I am trying to write a query which lists all A/P Reserve Invoice info with OPEN status.
I check the OPCH table and cannot find the rule to tell the status.
The "DocStatus" field has two values only: 'O' for open and 'C' for closed.
However, the status of A/P Reserve Invoice are OPEN, CLOSED, DELIVERED, PAID, etc.
I try to use DocStatus field to filter, but the result does not match what I see in SAP.
Could you please give me some hints about how to get the data I need? Thank you.
Best regards,
Sylvia
Edited by: csylvia on Jun 23, 2011 5:54 AMHi Darius,
Thanks for your reply.
However, I don't know what is the relationship between Purchase order and A/P Reserve Invoice.
Do you mean using "SELECT T0.DocEntry FROM OPCH T0, OPOR T1 WHERE T0.DocNum = T1.DocNum AND T1.DocStatus = 'O';" to query the A/P Reserve Invoice data with OPEN status?
But the result is not what I want.
The result of "*SELECT * FROM OPOR WHERE DocStatus = 'O';*" is also not.
I'd like to query A/P Reserve Invoice list with OPEN status, and I try the following sql query:
SELECT DocEntry FROM OPCH WHERE DocStatus = 'O' AND InvntSttus = 'O';
The result is close to what I need, but it's not exactly correct.
Moreover, I don't think the sql query conditions is accurate.
Please give me some advice. Thank you.
Best regards,
Sylvia -
How do you obtain SEQ_ID of a collection based on a SQL QUERY
I don't know if my brain is not working or what, but how can I access the seq_id of a collection that I display as a SQL Query? I have this SQL Query:
select
htmldb_item.checkbox(1,b.asset_id) " ",
htmldb_item.select_list_from_lov(2,
'SHARE-UNRESTRICTED','LOV_RESERVATION_MODE',null,'YES') "mode",
a.seq_id,
b.asset_no,
b.device_name,
b.device_name_attached_to
from
htmldb_collections a,
asset_report_vw b
where
a.collection_name = 'CART'
and a.c001 = b.asset_id
The user can select the reservation mode from the select list for the Mode field and hit a button to update the cart. I have reviewed documentation and the Collections Showcase demo that showed how to do this with form items, but not from a report. I can't figure out how to get the seq_id to pass to the HTMLDB_COLLECTION.UPDATE_MEMBER_ATTRIBUTE procedure. I tried to create a hidden region item called P9_SEQID but I can't figure out how to set it to the seq_id returned from a query. Using #SEQ_ID# syntax doesn't work.I am including the seq_id in my SQL Query report. The sticky point was how to reference the seq_id in an AFTER SUBMIT process to update the collection returned by the SQL Query when the user hit the Apply Changes button (they can edit one of the fields).
So, I assume then this is how I need to do it. I thought there might be a more efficient way to do it by somehow referencing the seq_id column in the SQL Query report instead of having to requery to get the seq id for each row in the SQL Query:
-- 'update_cart' AFTER SUBMIT process
DECLARE
v_seqid number := null;
BEGIN
FOR I in 1..HTMLDB_APPLICATION.G_F02.COUNT LOOP
select x.seq_id into v_seqid from htmldb_collections x
where x.collection_name = 'CART'
and c001 = htmldb_application.g_f01(i);
HTMLDB_COLLECTION.UPDATE_MEMBER_ATTRIBUTE(
p_collection_name => 'CART',
p_seq => v_seq_id
p_attr_number => 2,
p_attr_value => htmldb_application.g_f02(i));
END LOOP;
END;
Maybe you are looking for
-
Timeout error when submitting feedburner podcast feed to itunes
This is my first time submitting my podcast to itunes, I have created the feed with feedburner and I can manually subscribe and download the podcast in itunes however when i try to submit the feed I recieve the generic timout error, see below. I have
-
Video import quality poor on iMovie 4.0.1
Hi- I've not imported video from my miniDV camera for awhile and I seem to have a serious reduction in quality from previous projects. The images on the LCD of the camera are nice and bright and crisp but the images in iMovie are dark and grainy. I'v
-
Table to find position's person area, description
Hi Experts, I need to find the position's person area and the description, For ex: for each position there will be person area maintained,I want to find all the person area's for a list of positions. Can you please help me on this? Thanks in advance
-
Essbase Studio, Grid is not well formed !!
Hi All, Everything in Studio is prepared for a drill through on an Essbase model. A report is created and after pressing the button Show Result the first 20 rows appear on the screen. Switching to SmartView a selection is made and on a cell a balloon
-
is there a way to increase the number of background log writer processes in oracle 10g on unix platform