Is this Join Query Syntax Correct???
Is this syntax correct for this query question? Would "used Vista cards" reflect the OrderDate Column in the where clause. The table is from Adventureworks2012.
How many Sales Orders (Headers) used Vista credit cards in October 2002
SELECT C.CardType, COUNT(*)
FROM Sales.SalesOrderHeader S
JOIN Sales.CreditCard
C
ON S.CreditCardID=c.CreditCardID
WHERE C.CardType = 'Vista'
AND S.OrderDate between '10/1/2002' and '10/31/2002'
GROUP BY c.CardType
That is correct, but be careful when writing queries where a datetime column is compared to a period of time. In this case it looks like the time portions of OrderDate are all set to the beginning of day (00:00:00.000) so your query works as long as
that assumption is correct. The better way is to use an upper boundary of the next day (which means you cannot use between). E.g.,
select ... where S.OrderDate >= '20021001' and S.OrderDate < '20021101'
group by ...
order by ...;
If you search for the forum for "Tibor" you should be able to find a link to his website where he goes into much more detail about the tricky usage of the datetime datatype.
Similar Messages
-
Please help me correct this syntax on a question from a practice book. I am using the Adventureworks 2012 Database .
Find the Territory Group, CountryRegionCode, Count of SalesHeaders in 2001, and the Count of SalesDetails in 2001
SELECT C.[Group], C.CountryRegionCode, COUNT(A.SalesOrderID), COUNT(B.SalesOrderID)
FROM [Sales].[SalesOrderHeader] A
INNER JOIN
[Sales].[SalesOrderDetail] B
ON A.SalesOrderID=B.SalesOrderID
INNER JOIN
[Sales].[SalesTerritory] C
ON C.[TerritoryID]=A.TerritoryID
WHERE DATEPART(YY,A.OrderDate) IN (2001)
GROUP BY
C.[Group], C.CountryRegionCodeHi,
There is no error and query works perfectly fine but there is not output coming because there is no data for 2001 qualify the criteria.
I checked this for 2007 and got the result as below.
Please let me know if your question was something different.
Thanks,
Nimit -
I have this query, however... I need the 'category' variable
to be 'LIKE' but the way I have it set up it doent work. Anyone
have an idea of how I might fix this.
<CFQUERY name="getworkshops" datasource="source">
SELECT m.category, m.proj_key, m.project, r.proj_key, r.url,
r.category, r.end_date, r.title, e.event_date, e.event_date_end,
e.category, e.proj_key
FROM (main m INNER JOIN resource r ON m.category LIKE
r.category)INNER JOIN event_cal e ON m.category LIKE e.category
WHERE m.category like '%workshop%' AND m.proj_key=r.proj_key
AND m.proj_key = e.proj_key
ORDER BY m.proj_key
</CFQUERY>You could move your join statements to your where clause:
SELECT m.category, m.proj_key, m.project, r.proj_key, r.url,
r.category, r.end_date, r.title, e.event_date, e.event_date_end,
e.category, e.proj_key
FROM main m, resource r, event_cal e
WHERE m.category LIKE '%'+r.category+'%'
AND m.category LIKE '%" + e.category + '%'
AND m.category like '%workshop%' AND m.proj_key=r.proj_key
AND m.proj_key = e.proj_key
ORDER BY m.proj_key
I had to guess on how you wanted to match m.category against
resource and event_cal, but you get the idea. -
Query syntax corrections.
How can i define fdate & tdate as input variables instead of static data in this query?
declare @FDate nvarchar(8)='20120201'
declare @TDate nvarchar(8)='20140331'
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[Purchase Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode
--where TransType in ('18','19','20','21')
--and JDT1.RefDate between @FDate and @TDate
INNER JOIN (
select OPCH.TransId, OPCH.DocType, OPCH.ObjType FROM OPCH WHERE OPCH.DocDate BETWEEN @FDate and @TDate AND OPCH.DocType='I'
UNION ALL
select OPDN.TransId, OPDN.DocType, OPDN.ObjType FROM OPDN WHERE OPDN.DocDate BETWEEN @FDate and @TDate AND OPDN.DocType='I'
UNION ALL
select ORPD.TransId, ORPD.DocType, ORPD.ObjType FROM ORPD WHERE ORPD.DocDate BETWEEN @FDate and @TDate AND ORPD.DocType='I'
UNION ALL
select ORPC.TransId, ORPC.DocType, ORPC.ObjType FROM ORPC WHERE ORPC.DocDate BETWEEN @FDate and @TDate AND ORPC.DocType='I'
)TRANS ON JDT1.TransId=TRANS.TransId
group by OACT.AcctCode,OACT.AcctNameNagarajan,
Im forgot to post my entire code in my previous reply.Please have a look in the following code this report, contains several sub queries for financial auditing purposes .For every execution i need to change the date range dynamically. Im always execute this query directly in sql.But i want to change this query and let everyone to access and execute this from within SAP BI.Please help.
declare @FDate nvarchar(8)='20110101'
declare @TDate nvarchar(8)='20110131'
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[Purchase Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode
--where TransType in ('18','19','20','21')
--and JDT1.RefDate between @FDate and @TDate
INNER JOIN (
select OPCH.TransId, OPCH.DocType, OPCH.ObjType FROM OPCH WHERE OPCH.DocDate BETWEEN @FDate and @TDate AND OPCH.DocType='I'
UNION ALL
select OPDN.TransId, OPDN.DocType, OPDN.ObjType FROM OPDN WHERE OPDN.DocDate BETWEEN @FDate and @TDate AND OPDN.DocType='I'
UNION ALL
select ORPD.TransId, ORPD.DocType, ORPD.ObjType FROM ORPD WHERE ORPD.DocDate BETWEEN @FDate and @TDate AND ORPD.DocType='I'
UNION ALL
select ORPC.TransId, ORPC.DocType, ORPC.ObjType FROM ORPC WHERE ORPC.DocDate BETWEEN @FDate and @TDate AND ORPC.DocType='I'
)TRANS ON JDT1.TransId=TRANS.TransId
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[Sales Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode
--where TransType in ('13','14','15','16')
--and JDT1.RefDate between @FDate and @TDate
INNER JOIN (
select ODLN.TransId, ODLN.DocType, ODLN.ObjType FROM ODLN WHERE ODLN.DocDate BETWEEN @FDate and @TDate AND ODLN.DocType='I'
UNION ALL
select ORDN.TransId, ORDN.DocType, ORDN.ObjType FROM ORDN WHERE ORDN.DocDate BETWEEN @FDate and @TDate AND ORDN.DocType='I'
UNION ALL
select OINV.TransId, OINV.DocType, OINV.ObjType FROM OINV WHERE OINV.DocDate BETWEEN @FDate and @TDate AND OINV.DocType='I'
UNION ALL
select ORIN.TransId, ORIN.DocType, ORIN.ObjType FROM ORIN WHERE ORIN.DocDate BETWEEN @FDate and @TDate AND ORIN.DocType='I'
)TRANS ON JDT1.TransId=TRANS.TransId
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[Stock Taking Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode where TransType in ('58')
and JDT1.RefDate between @FDate and @TDate
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[SO/SIAmount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode where TransType in ('59','60')
and JDT1.RefDate between @FDate and @TDate
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[Inventory Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode where TransType in ('67')
and JDT1.RefDate between @FDate and @TDate
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[ Inventory Revaluation Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode where TransType in ('162')
and JDT1.RefDate between @FDate and @TDate
group by OACT.AcctCode,OACT.AcctName
select OACT.AcctCode,OACT.AcctName,SUM(JDT1.Debit-JDT1.Credit)[ Landed cost Amount] from JDT1
inner join oact on JDT1.Account=OACT.AcctCode where TransType in ('69')
and JDT1.RefDate between @FDate and @TDate
group by OACT.AcctCode,OACT.AcctName -
How can I perform this kind of range join query using DPL?
How can I perform this kind of range join query using DPL?
SELECT * from t where 1<=t.a<=2 and 3<=t.b<=5
In this pdf : http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,
It shows how to perform "Two equality-conditions query on a single primary database" just like SELECT * FROM tab WHERE col1 = A AND col2 = B using entity join class, but it does not give a solution about the range join query.I'm sorry, I think I've misled you. I suggested that you perform two queries and then take the intersection of the results. You could do this, but the solution to your query is much simpler. I'll correct my previous message.
Your query is very simple to implement. You should perform the first part of query to get a cursor on the index for 'a' for the "1<=t.a<=2" part. Then simply iterate over that cursor, and process the entities where the "3<=t.b<=5" expression is true. You don't need a second index (on 'b') or another cursor.
This is called "filtering" because you're iterating through entities that you obtain from one index, and selecting some entities for processing and discarding others. The white paper you mentioned has an example of filtering in combination with the use of an index.
An alternative is to reverse the procedure above: use the index for 'b' to get a cursor for the "3<=t.b<=5" part of the query, then iterate and filter the results based on the "1<=t.a<=2" expression.
If you're concerned about efficiency, you can choose the index (i.e., choose which of these two alternatives to implement) based on which part of the query you believe will return the smallest number of results. The less entities read, the faster the query.
Contrary to what I said earlier, taking the intersection of two queries that are ANDed doesn't make sense -- filtering is the better solution. However, taking the union of two queries does make sense, when the queries are ORed. Sorry for the confusion.
--mark -
How can i join this two query?
I have two table table employee and CSEReduxResponses
In table employee i have
CREATE TABLE [dbo].[employee](
[emp_id] [int] IDENTITY(1,1) NOT NULL,
[emp_namefirst] [varchar](255) NOT NULL,
[emp_namemiddle] [varchar](50) NULL,
[emp_namelast] [varchar](255) NOT NULL
on responds i have
CREATE TABLE [dbo].[CSEReduxResponses](
[response_id] [int] IDENTITY(1,1) NOT NULL,
[employee] [int] NOT NULL,
[employeedept] [int] NOT NULL,
[star] [tinyint] NOT NULL,
[status] [int] NOT NULL,
[approvedby] [int] NULL,
[approveddate] [datetime] NULL,
[execoffice_status] [int] NULL,
Im trying to get the employee with the MAX execpffice_status( this is either a 1 or 0).
i have this query that i made for it
select top(1) with ties employee, SUM(execoffice_status) as 'total'
from CSEReduxResponses
group by employee
order by 'total' desc
my query for employee table is
select emp_namefirst as first , emp_namelast as [last]
from phonelist.dbo.employee where emp_namefirst is not null
How can i get this 2 query together so i can output the employee (first and last )name
with the max exeoffice_status?
i use :
Microsoft SQL Server Management Studio 10.0.2531.0
ps: sorry if i put this is the wrong forum, this is my first time here and first post.Are you looking for the below?
CREATE TABLE [dbo].[employee](
[emp_id] [int] IDENTITY(1,1) NOT NULL,
[emp_namefirst] [varchar](255) NOT NULL,
[emp_namemiddle] [varchar](50) NULL,
[emp_namelast] [varchar](255) NOT NULL
Insert into Employee Values('abc','bcd','cdf')
Insert into Employee Values('xyz','yxw','xwv')
CREATE TABLE [dbo].[CSEReduxResponses](
[response_id] [int] IDENTITY(1,1) NOT NULL,
[employee] [int] NOT NULL,
[employeedept] [int] NOT NULL,
[star] [tinyint] NOT NULL,
[status] [int] NOT NULL,
[approvedby] [int] NULL,
[approveddate] [datetime] NULL,
[execoffice_status] [int] NULL,
Insert into [CSEReduxResponses]( employee,employeedept,star,status,approvedby,approveddate,execoffice_status)
Values(1,100,1,1,1,GETDATE(),0),
(1,100,1,1,1,GETDATE(),1),
(2,100,1,1,1,GETDATE(),0)
;With cte as( Select *,SUM([execoffice_status]) over(partition by Employee) sumstatus From [CSEReduxResponses] )
Select Distinct A.*,B.sumstatus
From Employee A
Inner Join cte B On A.emp_id = B.employee
--OR
;With cte as( Select employee ,SUM([execoffice_status]) sumstatus From [CSEReduxResponses] group by Employee)
Select Distinct A.*,(Select sumstatus From cte B where A.emp_id = B.employee)
From Employee A
Drop table Employee,[CSEReduxResponses] -
Updatable ResultSet for join Query
Hi all,
It is inevitable that i use a 'JOIN' operation for a particular query and i need the resultSet to be updated. Heard JDBC driver doesnt support this. Is there any workaround for this. Any help is really appreciated.
Thanks,
AbhijitWelcome to the forum!
>
It is inevitable that i use a 'JOIN' operation for a particular query and i need the resultSet to be updated. Heard JDBC driver doesnt support this.
>
As gimbal2 mentioned this isn't supported even by the latest 11g version and driver. See 'Result Set Limitations' in Chapter 17 of the JDBC doc for confirmation and discussion.
http://docs.oracle.com/cd/E14072_01/java.112/e10589/resltset.htm#BABBCECI
>
Result Set Limitations
The following limitations are placed on queries for enhanced result sets. Failure to follow these guidelines will result in the JDBC driver choosing an alternative result set type or concurrency type.
To produce an updatable result set:
A query can select from only a single table and cannot contain any join operations.
In addition, for inserts to be feasible, the query must select all non-nullable columns and all columns that do not have a default value.
A query cannot use SELECT * .
However, there is a workaround for this.
A query must select table columns only.
It cannot select derived columns or aggregates, such as the SUM or MAX of a set of columns.
>
>
Actually my exact requirement is i have two tables, earlier i used to select the results from one table and check for the existance of the corresponding record in the second table from the output of resultset. This is causing a lot of performance issue and i thought of using a single query by joining two tables which reduces the number of records.
>
So is this a correct description of what you want to do?
1. TableA and TableB have one or more columns in common.
2. Query TableA, possibly using filter predicates (WHERE tabA.col1 ...) and identify records in TableB that match on the join columns
3. Update the TableB records from step #2.
If so then you have a couple of options.
The record-by-record approach would be to execute your current query (the one that joins the two tables) but retrieve ONLY the ROWID from TableB. Then iterate thru the result set and use a separate query to get each TableB record by using the ROWID retrieved from the first query. This is different from your original approach because the first query WILL identify the TableB records you need it just won't retrieve them (only the ROWID).
Your original performance issues were probably because you were retrieving ALL of the TableA records and then checking each one to see if there were any TableB records for it.
The BULK approach would be a slight modification of of the record-by-record approach but pushes the work to the DB server.
This approach queries TableB to retrieve ONLY those records that EXIST in the query of TableA just described. So the query is of the form
SELECT * FROM TableB b WHERE EXISTS (SELECT '1' FROM TableA a WHERE a.col1 = b.col1); This query only uses one table for the resultset and does not contain any join operators so it can be updateable.
Test a simple query first until you get the syntax correct. -
Help with Inner Join query in SQL
Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
My table structure is :
table_packages
packageID
package
packageDetails
etc
table_destinations
destinationID
destination
destinationDetails
etc
table_packagedestinations
packageID
destinationID
..so nothing that complicated.
So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
This is the PHP from the header, including my INNER JOIN query....
PHP Code:
<?php
$ParampackageID_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
$ParamSessionpackageID_WADApackages = "-1";
if (isset($_SESSION['WADA_Insert_packages'])) {
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
$ParampackageID2_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
mysql_select_db($database_connPackages, $connPackages);
$query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
$WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
$row_WADApackages = mysql_fetch_assoc($WADApackages);
$totalRows_WADApackages = mysql_num_rows($WADApackages);
$colname_educationalDestinations = "1";
if (isset($_GET['PackageID'])) {
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
mysql_select_db($database_connPackages, $connPackages);
$query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
$educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
$row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
?>
And where I'm trying to display the destinations themselves, I have :
<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>
If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.
Thanks.First off, you need to get the database tables so that there is a relationship between them.
In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
table_packages
packageID
package
packageDetails
destination
destinationDetails
etc
If there is a one to many relationship, then the following would be true
packages
packageID
package
packageDetails
etc
destinations
destinationID
packageID
destination
destinationDetails
etc
The above assumes that there are many destinations to one package with the relationship coloured orange.
Once you have the above correct you can apply your query as follows
SELECT *
FROM packages
INNER JOIN destinations
ON packages.packageID = destinations.packageID
WHERE packages.packageID = %s
ORDER BY destination ASC
The above query will show all packages with relevant destinations -
Problem getting results with no unique key in a joined query
I created a descriptor to do a joined query, which generated a query in log as:
Select t0.empID,t1.empID, t1.phone from Emp t0, Phone t1
where t0.empId=t1.empId and t0.empId=1001
When I run it, I got the result as:
1001,1001,9999999
1001,1001,9999999
The correct result should be (I copy and paste the query from log into SQL-Plus):
1001,1001,9999999
1001,1001,1234455
I suspect this is caused by Toplink caching objects by primary key. I wonder if anybody has a solution for this.
My descriptor is created using WorkBench. Emp is the primary table, Phone as additional table linked by foreignKey empId.
The join is implemented by modifying the descriptor as the following:
ExpressionBuilder builder = new ExpressionBuilder();
descriptor.getQueryManage()
.setMultipleTableJoinExpression(
builder.getField("EMP.EMPID").equal(
builder.getField("EMP.EMPID")));
descriptor.disableCacheHits();
I'd really appreciate your help.I am implementing a people search function. The batch reading is quite expensive if toplink does a read query for every person. A customized query requires only one database access, the other way may requires hundreds.
I don't want to use the cache either in this case because the database is also accessed by legacy system which cann't notify toplink any updates.
I opened a TAR on this and the solution I got is to use ReportQuery rathen than ReadAllQuery. The only problem here is that now I have to map the query result to my class manually. -
MySQL InnerJoin query syntax error?
I can't seem to locate the syntax error in this MySQL query. Coldfusion says there an error in my sql syntax. Here is the query. Anyone have any clues on this?
<cfquery name="queryItem" datasource="bonus">
select
p.productid,
p.modelnumber,
p.modeldescription,
sp.sp_bonusamount as Amount
from
products i join bonusproducts sp on i productid = sp.sp_productid
inner join program p on sp.sp_programid = p.programid
where
p.CompanyOrgLevelID in (#getParentCompanyOrgLevelIDList(session.CompanyOrgLevelID)#)
and p.ProgramID = #programID#
<cfif categoryID gt 0>
and CategoryID in (#getSubcategoryIDList(categoryID)#)
</cfif>
order by
#sortColumn# #sortDirection#
</cfquery>To troubleshoot, run this:
select
p.productid,
p.modelnumber,
p.modeldescription,
sp.sp_bonusamount as Amount
from
products i join bonusproducts sp on i productid = sp.sp_productid
inner join program p on sp.sp_programid = p.programid
where 1 = 2
If it runs successfully, keep adding bits and pieces until it crashes. Then you'll know what made it crash.
Also enable debugging so you can see the sql that gets generated from your code. That's often useful. -
Database Toolkit Sub query Syntax and file path expectation question.
I need some assistance from those of you smarter than I.
I have two database files (not two tables in the same database file) one represents information delivered from an external interface, and the other is used by the internal interface associated with the processing half of my application. Data is received (i.e. fields are populated) from the external interface to one database file and that data is then copied to another database file where the information will be processed by the internal interface. This is being done because I am worried about file access issues that might occur if two different interfaces (external & internal) try to access the same file at the same time (without dealing with semaphores). I am not too worried about the sanctity of the data since each record supplied from the external interface should not effect any of the data being used by the internal interface. So the first question is , am I being to primitive in my thinking assuming that I would run into file access issues if I were to just use two tables in the same database file for the same purpose ?
My second question is related to my current implementation where I have two separate database files representing the external and internal interface data. Currently when a new set of data is entered into the External Interface Database file, an alert is issued, and another task copies the data from that file into Internal Interface Database, then the data is deleted from the External Interface Database file. My question is related to the syntax that I am using to provide the described functionality. I am currently using a INSERT with a subquery to the External Interface Database file i.e. INSERT INTO InternalDB FROM ExternalDB.ExternalTable WHERE Order = '06306049'; .
My question is when I run this query with both database files in same directory I get an error stating that the ODBC driver can not find the ExternalDB.ExternalTable in the Parent Directory of the subdirectory where the files are actually located. The system DSN is set up correctly for the ExternalDB, and if I move it to the parent directory the query works correctly, my question is why would I have to put the two database files in seperate directories for this to work and is there a way to avoid this ?
Thanks..
Brad WThanks for responding Brian -
The message I get is Error Code -2147467259
Conn Execute.vi->InsertIntoFrom.vi<ERR>Exception occured in Microsoft OLE DB Provider for ODBC Drivers: [Microsoft][ODBC Microsoft Access Driver] Could not find file 'C:\Project\APDSS\DataBase\ExternalInterface.mdb'. in Conn Execute.vi->InsertIntoFrom.vi
When my query looks like
INSERT INTO InternalInterface SELECT Field1, Field2 FROM ExternalInterface.ExternalTable WHERE Id = '065649-101-750'; -
MV Incremental Refresh on join query of remote database tables
Hi,
I am trying to create a MV with incremental refresh option on a join query with 2 tables of remote database.
Created MV logs on 2 tables in the remote database.
DROP MATERIALIZED VIEW LOG ON emp;
CREATE MATERIALIZED VIEW LOG ON emp WITH ROWID;
DROP MATERIALIZED VIEW LOG ON dept;
CREATE MATERIALIZED VIEW LOG ON dept WITH ROWID;
Now, trying to create the MV,
CREATE MATERIALIZED VIEW mv_emp_dept
BUILD IMMEDIATE
REFRESH FAST
START WITH SYSDATE
NEXT SYSDATE1/(24*15)+
WITH PRIMARY KEY
AS
SELECT e.ename, e.job, d.dname FROM emp@remote_db e,dept@remote_db d
WHERE e.deptno=d.deptno
AND e.sal>800;
Getting ORA-12052 error.
Can you please help me.
Thanks,
AnjanPrimary Key is on EMPNO for EMP table and DEPTNO for DEPT table.
Actually, I have been asked to do an feasibility test whether incremental refresh can be performed on MV with join query of 2 remote database tables.
I've tried with all combinations of ROWID and PRIMARY KEY, but getting different errors. From different links, I found that it's possible, but cannot create any successful testcase anyway.
It will be very much helpful if you can correct my example or tell me the restrictions in this case.
Thanks,
Anjan -
Hi Guriji,s
I wrote one inner join query. it is working fine. but when i exceute this query it is fetching the data only 261 movement type but but i also fetch the data movement type 201. for this plz tell me the correction in this query.
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and abwart = '261' or a~bwart = '201'
and btcode2 = 'mb1a' or btcode2 = 'mfbf' .
thanks.Hi Sachin
try to use like below
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and ( abwart = '261' or a~bwart = '201' )
and ( btcode2 = 'mb1a' or btcode2 = 'mfbf' ).
or try to fill ranges like select-options or use like
select amatnr awerks abwart bbudat into table t_itab from mseg as a inner join mkpf as b
on amblnr = bmblnr
where awerks in plant and abwart in ('261', '201')
and btcode2 = 'mb1a' or btcode2 = 'mfbf' .
Regards
Praveen -
Self-join query to Analytical function query
Hi All,
I have converted a self-join query to Analytical function query due to the performance reasons.
Query which is using Analytical function is giving the correct count as I compared it with query using Self-Join. Can you please tell what is wrong in the query.
==========================
Query using Self-Join
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
================================================
Query Using Analytical function
select count(1)
From (select t1.*, max(t1.dw_creation_dt) over (partition by t1.empl_id) pers_max_date
from ohr_pers_curr t1 ) pers
, (select t2.*, max(t2.dw_creation_dt) over (partition by t2.empl_id, t2.empl_rcd) job_max_date
from OHR_JOB_CURR t2) job
where pers.empl_id = job.empl_id
and pers.dw_creation_dt=pers.pers_max_date
and job.dw_creation_dt=job.job_max_date
and job.dummy_row_flag = 'N'
and pers.dw_creation_rsn_cd in ('N', 'U')
and job.dw_creation_rsn_cd in ('N', 'U')
==================================Hi David,
The base is same but the problem is different.
As far as implementation concern these queries looks same, but when I see there counts, they do not match. I do not have any reason why this happening.
Regards
Gaurav -
Join query in a dynamic list of values query
I have a join query in a dynamic list of values query. The value does not return a text value, but rather the id value.
Is it possible to use a join query in a dynamic list of values query?
For example...in the below query, I expect to see ename in the drop down list, but I see class_emp_id.
select b.ename d, a.class_emp_id r
from class_emp a, emp b
where a.class_cat_id = :CURR_CLASS_CAT_ID
and a.emp_id = b.emp_id
order by 1
Thanks,
Reid:CURR_CLASS_CAT_ID is a number datatype.
I think the problem is with the ARF. Whenever I change the dynamic LOV query to exclude the :CURR_CLASS_CAT_ID (a passed in session variable), the drop down shows all the text names I am looking for; albeit, too many since I am excluding the :CURR_CLASS_CAT_ID.
The page I am having the problem with is a popup that is called from a report link on another page. When I show the session variables on the popup page, it shows values for only 1 of the 3 session variables I am passing to this page.
I am using the javascript:popUp2 syntax when I call the popup page from the report link.
As I said previously, I am passing 3 parms and only the 1st parm is getting a value. Yes, there are values for all three parms in the record of the report.
Is there a limit to the number of variables (itemNames) that can be passed to the popup using this method?
Maybe you are looking for
-
the help pagers just bring me around in circles. the ipod doesn't show up in system devices under the busses. i've tried just about everything. Im using windows xp at home and though maybe it was because of that. so went to a relatives and used a
-
Before updating to OSx 10.4.4, you could choose the "Day starts at:" and "Day ends at:" preference to limit the amount of hours in the main iCal window in week view. Now changing that preference only grays out the unwanted hours. They are still there
-
Background image not rendering correctly in Chrome
Can anyone see what I've done wrong with this bg image? The footer has a 1 px wide repeating bg image which is fine in all the usual browsers except Chrome - getting the same effect in live view so obviously done something wrong, but can't find it.
-
Prevent changes to PO before released
Once a release strategy is invoked for a PO, I'd like to be able to prevent/lock the PO from changes until it has been released. I noted that on the PR release indicators there is a way to set the PR to display only (via the field selection key). I c
-
I'm getting a "paper jam" warning in a HP 4500 wireless. There is no jam.
Officejet 4500 wireless....windowsXP-home...."paper jam" There is no paper jam!