Two ForeignKey to define in the same table
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class CustomerBase
public CustomerBase()
this.Payments = new List<PaymentBase>();
this.Documents = new List<DocumentBase>();
this.OwnerShips = new List<OwnerShipBase>();
[Key]
public Int64 MusteriId { get; set; }
public string KimlikNo { get; set; }
public string Unvan { get; set; }
public byte[] MusteriResim { get; set; }
public virtual ICollection<OwnerShipBase> OwnerShips { get; set; }
public virtual ICollection<PaymentBase> Payments { get; set; }
public virtual ICollection<DocumentBase> Documents { get; set; }
and
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class OwnerShipBase
public OwnerShipBase()
this.Payments = new List<PaymentBase>();
this.Documents = new List<DocumentBase>();
[Key]
public Int64 IsId { get; set; }
public Int64 MusteriId { get; set; }
[ForeignKey("MusteriId")]
public virtual CustomerBase CustomerBase { get; set; }
public DateTime? Tarih { get; set; }
public string Acıklama { get; set; }
public virtual ICollection<PaymentBase> Payments { get; set; }
public virtual ICollection<DocumentBase> Documents { get; set; }
and
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class PaymentBase
[Key]
public Int64 OdemeId { get; set; }
public Int64 MusteriId { get; set; }
[ForeignKey("MusteriId")]
public virtual CustomerBase CustomerBase { get; set; }
public Int64 IsId { get; set; }
[ForeignKey("IsId")]
public virtual OwnerShipBase OwnerShipBase { get; set; }
public DateTime? Tarih { get; set; }
public Decimal? Nakit { get; set; }
and
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
public class DocumentBase
[Key]
public Int64 DosyaId { get; set; }
public Int64 MusteriId { get; set; }
[ForeignKey("MusteriId")]
public virtual CustomerBase CustomerBase { get; set; }
public Int64 IsId { get; set; }
[ForeignKey("IsId")]
public virtual OwnerShipBase OwnerShipBase { get; set; }
public string DosyaAdi { get; set; }
public byte[] DosyaBinary { get; set; }
and
using EntityModels;
using System.Data.Entity;
public class DataContext:DbContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
public DbSet<CustomerBase> CustomerBases { get; set; }
public DbSet<OwnerShipBase> OwnerShipBases { get; set; }
public DbSet<PaymentBase> PaymentBases { get; set; }
public DbSet<DocumentBase> DocumentBases { get; set; }
And
public static bool InsertCustomer(CustomerBase Kaydet)
using (var db = new DataContext())
db.CustomerBases.Add(Kaydet);
return( db.SaveChanges() > 0);
error;
System.Data.SqlClient.SqlException was unhandled by user code
HResult=-2146232060
Message=Introducing FOREIGN KEY constraint 'FK_dbo.OwnerShipBases_dbo.CustomerBases_MusteriId' on table 'OwnerShipBases' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=1785
Procedure=""
Server=.\SQLEXPRESS
State=0
StackTrace:
konum: System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
konum: System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
konum: System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
konum: System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
konum: System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite)
konum: System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
konum: System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
konum: System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
konum: System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
konum: System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
konum: System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteSql(MigrationStatement migrationStatement, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbTransaction transaction, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinTransaction(IEnumerable`1 migrationStatements, DbTransaction transaction, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsWithinNewTransaction(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection, DbInterceptionContext interceptionContext)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable`1 migrationStatements, DbConnection connection)
konum: System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClass30.<ExecuteStatements>b__2e()
konum: System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
konum: System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
konum: System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements, DbTransaction existingTransaction)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable`1 migrationStatements)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.ExecuteStatements(IEnumerable`1 migrationStatements)
konum: System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, VersionedModel targetModel, IEnumerable`1 operations, IEnumerable`1 systemOperations, Boolean downgrading, Boolean auto)
konum: System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading)
konum: System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
konum: System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
konum: System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
konum: System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
konum: System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
konum: System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
konum: System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
konum: System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
konum: System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
konum: System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
konum: System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
konum: System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
konum: System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
konum: System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
konum: System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
konum: System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
konum: System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
konum: System.Data.Entity.Internal.InternalContext.Initialize()
konum: System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
konum: System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
konum: System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
konum: System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
konum: System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
konum: System.Data.Entity.DbSet`1.Add(TEntity entity)
konum: CCTrackingBase.EntityQueries.Customer.InsertCustomer(CustomerBase Kaydet) e:\Data_Backup\Özel_Programlarım\Kenan YILMAZ\CCTrackingDesktop\CCTrackingBase\EntityQueries\Customer.cs içinde: satır 16
konum: CCTrackingDesktop.MainWindow.Ekle() e:\Data_Backup\Özel_Programlarım\Kenan YILMAZ\CCTrackingDesktop\CCTrackingDesktop\AnaPanel.xaml.cs içinde: satır 47
konum: CCTrackingDesktop.MainWindow..ctor() e:\Data_Backup\Özel_Programlarım\Kenan YILMAZ\CCTrackingDesktop\CCTrackingDesktop\AnaPanel.xaml.cs içinde: satır 20
InnerException:
I want to make ForeignKey IsId and musteriId areas but I did not succeed;Thanks for your help
Hello Kenan,
>>I want to make ForeignKey IsId and musteriId areas but I did not succeed;
With your provided model, I made a test with and reproduced this issue and this issue is caused by a cause cycles or multiple cascade paths, the exception message also mentions and it actually provided the workaround which Specify ON DELETE NO ACTION or
ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. In the OnModelCreating method of your context class, adding code as below:
modelBuilder.Entity<PaymentBase>().HasRequired(p => p.CustomerBase).WithMany().WillCascadeOnDelete(false);
modelBuilder.Entity<PaymentBase>().HasRequired(p => p.OwnerShipBase).WithMany().WillCascadeOnDelete(false);
modelBuilder.Entity<DocumentBase>().HasRequired(p => p.CustomerBase).WithMany().WillCascadeOnDelete(false);
modelBuilder.Entity<DocumentBase>().HasRequired(p => p.OwnerShipBase).WithMany().WillCascadeOnDelete(false);
On my side, the model generates the database successfully.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey.
Similar Messages
-
Hi,
I want to center two different text row that are in the same table but one on the center and the other one on the left. I put a <span> tag hoping that it has been overwhelmed the table's class properties The .bottomsel's font-family and the .Cig84's font-family and colour work but the text-align don't: they're both on the left.
These are my source and CSS codes:
Source:
<table width="600" border="0">
<tr>
<td class="bottomref"><p><span class="bottomsel">| <a href="index.html" target="_self">Main</a> | <a href="about.html" target="_self">About</a> | <a href="clients.html" target="_self">Clients</a> | <a href="contact.html" target="_self">Contact</a> |</span><br />
<span class="credits">Credits: <span class="Cig84">Cig84</span></span></p></td>
</tr>
</table>
CSS:
.bottomsel {
text-align: center;
font-family: Georgia, "Times New Roman", Times, serif;
.credits {
text-align: left;
.Cig84 {
color: #F00;
font-family: "Comic Sans MS", cursive;Use paragraph tags with CSS classes.
CSS:
.center {text-align:center}
.left {text-align:left}
HTML:
<table width="600" border="0">
<tr>
<td class="bottomref">
<p class="center">This text is center aligned</p>
<p class="left">This text is left aligned</p>
</td>
</tr>
</table>
Nancy O. -
Two LOVs in same UIX page based on the same table
Hi group,
Recently I ran into a problem with a UIX page that has two LOVs based on the same database table. In Emp and Job terminology, here's what I tried to do.
Suppose we have use the Employees and Jobs tables from the HR scheme with one small modification. Add a column called PREFERRED_JOB_ID of type VARCHAR2(10) which is exactly the same as JOB_ID. Hypothetically speaking, this column will be used to allow Employees to select their preferred job in case they want to change their jobs.
Next, create business components in JDeveloper based on the Employees and Jobs table. In order to be able to generate the LOVs for Job and PreferredJob create two ViewObjects, one called JobsLookupView and one called PreferredJobsLookupView. These both need to be based upon the same Jobs EntityObject. Also include the Jobs EntityObject twice in the EmployeesView ViewObject and give one the alias PreferredJobs. Include the JobTitle attributes of Jobs and PreferredJobs in EmployeesView so they can contain the JobTitles selected in our future LOVs.
Next create a ViewController project if it's not already there and enable JHeadstart on it. Create an Application Structure File and create the lookups for the two LOVs. When I run the application I see this happening:
When I click the flashlight icon next to the PreferredJob LOV and select a job, the PreferredJob field is selected in the UIX page but no job title appears. When I next first select the Job LOV and select a new job and then select the PreferredJob LOV again and select a different job, the job that was selected in the Job LOV is now also entered in the PreferredJob field. When I make sure the PreferredJob field isn't required (remove the required="yes" property on the messageLovInput entry for PreferredJobTitle and remove the PreferredJobTitle field from the addRequiredRowItems list in the UIX page) I can save the changes I made in the Employees.uix page. The same JobId is stored in the database for Job and PreferredJob.
This behaviour is probably due to cacheing issues because both LOVs and the EmployeesView ViewObject use one EntityObject for four values in three ViewObjects.
So I then modified my model a bit. I created a new EntityObject called PreferredJobs based on the JOBS table. I modified the EmployeesView ViewObject to use this EntityObject for the PreferredJobTitle attribute and modified the PreferredJobsLookupView to use this EntityObject.
I needed to modify a few things as well in the Application Structure File (which were prompts and whether or not the attribute should be visible in a table) and after regenerating I made sure the PreferredJob attribute isn't required in the UIX page. When I then run the application again, I never see the JobTitle I select in any LOV allthough the PreferredJob field is selected when I select a Job in the PreferredJob LOV. The correct JobId now is stored in the database though.
Has anyone ever encoutered this behaviour? Would anyone know how to get two LOVs based on the same table in one UIX page?
Thanks in advance,
Wouter van Reeven
AMISOK I figured it out. When I added the second Lookup ViewObject (PreferredJobs) no additional Association was created. Therefore, ADF BC wasn't able to figure out which field to update. When I added the Association between the PreferredJobs Lookup ViewObject and the Employees ViewObject everything started working ok.
I then recreated my inital situation: one EntityObject for Jobs and one for Employees, now with two Associations between them. After modifying the Employees ViewObject and making sure the Jobs EntityObject was referred twice and via the corresponding Association, everything started working ok.
Greets, Wouter
AMIS -
SUM two fileds from different rows from the same table
I would like to SUM two fileds from different rows from the same table but I don't know how to do that.
E.g.
BillingTransactionsIndex CreateDate UserType UserIndex TransType Reference Total Balance
2 6/5/2008 15:02 1 51 1 150 -288.2 -288.2
5 6/8/2008 11:55 1 51 1 157 -1.58674 -289.787
In the table above I want SUM fields Total and Balance for the first row and the the next row SUM 2nd row Total with 1st row Balance
Please help
ThanksSQL> with tbl as
2 (select 1 as ID, 90 as total from dual
3 union all
4 select 2 as ID, 23 as total from dual
5 union all
6 select 3 as ID, 15 as total from dual
7 union all
8 select 4 as ID, 20 as total from dual)
9 select id , total, sum(total) over (order by ID) as balance from tbl
10 /
ID TOTAL BALANCE
1 90 90
2 23 113
3 15 128
4 20 148
SQL> -
SUM two ROWS in the SAME Table
Hi,
I have a problem with this issue. I want to sum two rows from the same table, but I don´t know how to do that. I tried to do it with CTE, but always I get the same error "Ambiguous". I would like to ask you, if there is other manner to get that
data (sum two rows) and if it is possible to see examples about it.
Thank you in advanceHi Vaibhav,
I leave you my scrip:
USE Modelling
GO
--TABLE Aer_Lingus_Income_Statement
IF OBJECT_ID('Aer_Lingus_Income_Statement') IS NOT NULL
DROP TABLE Aer_Lingus_Income_Statement
GO
CREATE TABLE Aer_Lingus_Income_Statement
ID [nvarchar](255) NOT NULL,
Name_Account [nvarchar](255) NULL,
Company [nvarchar](255) NULL,
Level0_Account [nvarchar](255) NULL,
Level1_Account [nvarchar](255) NULL,
Level2_Account [nvarchar](255) NULL,
Level3_Account [nvarchar](255) NULL,
Level4_Account [nvarchar](255) NULL,
Level5_Account [nvarchar](255) NULL,
Level6_Account [nvarchar](255) NULL,
Level7_Account [nvarchar](255) NULL,
Level8_Account [nvarchar](255) NULL,
Year_2006 decimal (15,2) null,
Year_2007 decimal (15,2) null,
Year_2008 decimal (15,2) null,
Year_2009 decimal (15,2) null,
Year_2010 decimal (15,2) null,
Year_2011 decimal (15,2) null,
Year_2012 decimal (15,2) null,
Year_2013 decimal (15,2) null,
GO
ALTER TABLE Aer_Lingus_Income_Statement
ADD CONSTRAINT PK_Aer_Lingus_Income_Statement PRIMARY KEY (ID)
GO
INSERT INTO Aer_Lingus_Income_Statement
SELECT *
FROM Aer_Lingus_data_Income
IF OBJECT_ID('Aer_Lingus_Income_Statement_Historic') IS NOT NULL
DROP VIEW Aer_Lingus_Income_Statement_Historic
GO
CREATE VIEW Aer_Lingus_Income_Statement_Historic
as
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Revenue'
Group by Level0_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Passenger revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Ancillary revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Other revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account= 'Cargo revenue' and Level0_Account ='Revenue'
Group by Name_Account
UNION ALL
Select Level0_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level0_Account ='Operating expenses'
Group by Level0_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Staff costs' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Depreciation, amortisation and impairment' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Aircraft operating lease costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Fuel and oil costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Maintenance expenses' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Airport charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='En-route charges' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Distribution costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Ground operations, catering and other operating costs' and Level0_Account ='Operating expenses'
Group by Name_Account
UNION ALL
Select Level1_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Level1_Account ='Other (gains)/losses - net' and Level0_Account ='Operating expenses'
Group by Level1_Account
UNION ALL
Select Name_Account , sum(Year_2006) as Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
Where Name_Account ='Employee profit share' and Level0_Account ='Operating expenses'
Group by Name_Account
GO
WITH sumasRevenue
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Revenue'
GROUP BY Name_Account, ID
WITH ROLLUP
, total
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasRevenue
WHERE Name_Account IS NULL
sumasOperatingExpensive
AS (
SELECT Name_Account, ID
, sum(Year_2006) AS Y2006, sum (Year_2007) as Y2007, sum (Year_2008) as Y2008, sum (Year_2009) as Y2009, sum (Year_2010) as Y2010,
sum (Year_2011) as Y2011, sum (Year_2012) as Y2012, sum (Year_2013) as Y2013
FROM Aer_Lingus_data_Income
WHERE Level0_Account = 'Operating expenses'
GROUP BY Name_Account, ID
WITH ROLLUP
, total1
AS (
SELECT Y2006,Y2007 ,Y2008,Y2009 ,Y2010 ,Y2011 ,Y2012 ,Y2013
FROM sumasOperatingExpensive
WHERE Name_Account IS NULL
SELECT distinct ID , s.Name_Account,
(s.Y2006* 1.0 - t.Y2006) AS [V2006] ,(s.Y2007* 1.0 -T.Y2007 ) as [V2007] , (s.Y2008* 1.0 /T.Y2008 ) as [V2008],(s.Y2009* 1.0 /T.Y2009 ) as [V2009],
(s.Y2010* 1.0 /T.Y2010 ) as [V2010],(s.Y2011* 1.0 /T.Y2011 ) as [V2011],(s.Y2012* 1.0 /T.Y2012 ) as [V2012],(s.Y2013* 1.0 /T.Y2013 ) as [V2013]
FROM sumasRevenue AS s , sumasOperatingExpensive AS t
Where ID IS NOT NULL
UNION ALL
SELECT distinct ID,COALESCE(s.Name_Account,'NON CURRENT ASSETS') AS Name_Account ,
sum (s.Y2006* 1.0 / t.Y2006) as V2006,sum (s.Y2007* 1.0 / t.Y2007) as V2007,sum (s.Y2008* 1.0/ t.Y2008) as V2008,sum (s.Y2009* 1.0/ t.Y2009) as V2009,sum (s.Y2010* 1.0/ t.Y2010) as V2010,
sum (s.Y2011* 1.0 / t.Y2011) as V2011,sum (s.Y2012* 1.0/ t.Y2012) as V2012,sum (s.Y2013* 1.0/ t.Y2013) as V2013
FROM sumasRevenue as s , sumasOperatingExpensive as t
Where ID IS NULL and Name_Account IS NULL
GROUP BY Name_Account, ID
WITH ROLLUP
select *
from Aer_Lingus_Income_Statement_Historic
Thank you in advance -
Persistence two beans in the same table, Duplicate table name in different beans
Hi,
I need to persist two beans belonging to different classes in the same
table, but the following mistake happens:
[jdo-enhance] javax.jdo.JDOFatalUserException: Invalid jdbc-table-name:
Duplicate table name
There exists some way of persisting both objects in the same table?
thanks
jasabinoNo. It would be very confusing to do so. Can they not share an
inheritance hierarchy? You can use flat mapping to do so.
Jose wrote:
Hi,
I need to persist two beans belonging to different classes in the same
table, but the following mistake happens:
[jdo-enhance] javax.jdo.JDOFatalUserException: Invalid jdbc-table-name:
Duplicate table name
There exists some way of persisting both objects in the same table?
thanks
jasabino -
Two triggers in the same table and event
If I created two triggers on the same table and event (before insert), which of them will be triggered first ?...
The problem from the beginning is that I created the second one as after insert and in the body of the trigger I wrote (:new.xxx:= value) ... then an error (that it should be before insert trigger or update trigger), so I created it as before update ,,, but I have already before update trigger (for primary key)..... and the problem -I think- which of them start first...
Can make the second one as after insert and make update statement instead of assigning (:new.xxx:= value).....
RegardsIf I created two triggers on the same table and event
(before insert), which of them will be triggered
first ?...As already mentioned, prior to 11g the order of firing is undetermined.
The problem from the beginning is that I created the
second one as after insert and in the body of the
trigger I wrote (:new.xxx:= value) ... then an error
(that it should be before insert trigger or update
trigger), so I created it as before update ,,, but I
have already before update trigger (for primary
key)..... and the problem -I think- which of them
start first...If there is a conflict of interest inside the code then you will have to alter your design principle around this to cater for it. Also consider combining the code into a single before insert trigger to prevent any confusion.
Can make the second one as after insert and make
update statement instead of assigning (:new.xxx:=
value).....Attempting to update or query the same table as is causing the trigger to fire will result in a mutating table error. You can't do this. -
Compare two results from the same table
i have two results from the same table that i would like to compare. below is my query and the results i want to compare
SELECT tblItemRoutingBOM.ItemRevID, tblItem.ItemID, tblItem.PartNum, tblItem.ItemName, tblItem.ManufacturerPartNum AS [Mfg Part#], tblItemRoutingBOM.Quantity
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
WHERE tblItemRoutingBOM.ItemRevID in (61,70)
as you can see i am returning two records using the where clause
ItemRevID, ItemID, PartNum, ItemName, Manufacturer, Mfg Part#, Quantity
61,121,331503,.233 Aluminum Sheet,,1
70,121,331503,.233 Aluminum Sheet,,3
now what i am looking for is to combine these two together into one row with the following added. two columns for each QTY, QTY1 = 1 and QTY2 = 3 with a third column added that is the difference between the two QTY Diff = 2
Any thoughts?Here are the two statements that i want to combine, results for each are attached
SELECT tblItem.ItemID, Sum(tblItemRoutingBOM.Quantity) AS SumOfQuantity, tblItem.PartNum AS [Part #],
tblItem.ItemName, tblManufacturer.ManufacturerName AS Manufacturer, tblItem.ManufacturerPartNum AS [Mfg Part#]
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
INNER JOIN tblUnits ON tblItem.UnitID = tblUnits.UnitID
LEFT JOIN tblManufacturer ON tblItem.ManufacturerID = tblManufacturer.ManufacturerID
WHERE tblItemRoutingBOM.ItemRevID=61
GROUP BY tblItem.ItemID,tblItem.PartNum,tblItem.ItemName,tblManufacturer.ManufacturerName,tblItem.ManufacturerPartNum
SELECT tblItem.ItemID, Sum(tblItemRoutingBOM.Quantity) AS Quantity, tblItem.PartNum AS [Part #],
tblItem.ItemName, tblManufacturer.ManufacturerName AS Manufacturer, tblItem.ManufacturerPartNum AS [Mfg Part#]
FROM tblItemRouting
INNER JOIN tblItemRoutingBOM ON tblItemRouting.ItemRoutingID = tblItemRoutingBOM.ItemRoutingID
INNER JOIN tblItem ON tblItemRoutingBOM.ItemID = tblItem.ItemID
INNER JOIN tblUnits ON tblItem.UnitID = tblUnits.UnitID
LEFT JOIN tblManufacturer ON tblItem.ManufacturerID = tblManufacturer.ManufacturerID
WHERE tblItemRoutingBOM.ItemRevID=70
GROUP BY tblItem.ItemID,tblItem.PartNum,tblItem.ItemName,tblManufacturer.ManufacturerName,tblItem.ManufacturerPartNum
114,11,55002,Pepsi Blue Cap,NULL,
117,5,331501,Marigold Yellow For ABS,NULL,
121,1,331503,.233 Aluminum Sheet,NULL,
125,2,331504,Velvet Vinyl .008,NULL,
114,33,55002,Pepsi Blue Cap,NULL,
117,15,331501,Marigold Yellow For ABS,NULL,
121,3,331503,.233 Aluminum Sheet,NULL,
125,6,331504,Velvet Vinyl .008,NULL,
my returned result should combine above with two extra columns (two extra columns because i have two results to combine)
114, 11, 33, 22, 55002, Pepsi Blue Cap, NULL,
117, 5, 15, 10, 331501, Marigold Yellow For ABS, NULL
121,1, 3, 2, 331503, .233 Aluminum Sheet, NULL
125, 2, 6, 4, 331504, Velvet Vinyl .008, NULL
Columns go as such, ID, QTY1 (for 61), QTY2 (for 70), Diff (QTY1-QTY2), PartNum, ItemName, Mfg, Mfg Part#
IF the results from one of those two are empty then i would see something like this
114, 11, 0, 11, 55002, Pepsi Blue Cap, NULL,
117, 5, 0, 5, 331501, Marigold Yellow For ABS, NULL
121,1, 0, 1, 331503, .233 Aluminum Sheet, NULL
125, 2, 0, 2, 331504, Velvet Vinyl .008, NULL -
Two diffferent type of joins on the same table
I have a query that, it seems, requires me to two two different types of joins to the same table.
from table t1
LEFT OUTER JOIN table2 t2
ON t1.col1= t2.col1
and t1.col2 = t2.col2
and t1.col5 = t2.col5
LEFT OUTER JOIN table2 t3
ON t1.col1= t3.col1
and t1.col2 = t3.col2
and t1.col4 = t3.col4
would I run into a problem if I just did:
LEFT OUTER JOIN table2 t2
ON t1.col1= t2.col1
and t1.col2 = t2.col2
and t1.col3 = t2.col3
and t1.col4 = t2.col4
and t1.col5 = t2.col5
And if I go with option 1 and I also create two different types of indexes to accommodate each join, will 10g know which ones to use?
Message was edited by:
user623359
Message was edited by:
user623359No version number and no statement of what it is you are trying to do ... but one solutions is to use the traditional Oracle syntax and the first part, then wraps it in parentheses turning it into an inline view, and then join that to the next part.
-
Calculating average time from two records from the same table.
Hi all
I need to calculate the average time between two events that are recorded in the same table.
The table is TMS_MESSAGE_AUDIT_LOG
MESSAGE_ID VARCHAR2(16 BYTE) NOT NULL,
MESSAGE_VERSION NUMBER(2) NOT NULL,
CREATE_TM VARCHAR2(18 BYTE) NOT NULL,
MESSAGE_STATUS VARCHAR2(30 BYTE),
TRANSACTION_TYPE_NM VARCHAR2(30 BYTE),
MESSAGE_TP VARCHAR2(3 BYTE),
WORKFLOW_OBJECT VARCHAR2(30 BYTE) NOT NULL,
WORKFLOW_REQUEST VARCHAR2(30 BYTE) NOT NULL,
WORKFLOW_RETURN_CD VARCHAR2(30 BYTE) NOT NULL,
AUDIT_ACTION VARCHAR2(255 BYTE),
LAST_UPDATE_USER_LOGON_ID VARCHAR2(12 BYTE),
LOCAL_TM VARCHAR2(18 BYTE) NOT NULL,
LOCAL_TIME_ZN_NM VARCHAR2(70 BYTE) NOT NULL,
LOCAL_DAYLIGHT_IN CHAR(1 BYTE) NOT NULL,
FPRINT VARCHAR2(30 BYTE)
What i now need is
When the MESSAGE_ID is the same i need have the average time between when the MESSAGE_STATUS is AA and BB ( I need the time out of the CREATE_TM field )
And this for every 15 minutes interval.
Because this table will become BIG millions and millions of records it needs to be fast.
Can anybody help me.
MarcelSomething like this?
CREATE TABLE wr_test
( message_id VARCHAR2(16 BYTE) NOT NULL
, message_version NUMBER(2) NOT NULL -- Assumption: Acknowledged ver > Received ver
, create_tm VARCHAR2(18 BYTE) NOT NULL
, message_status VARCHAR2(30 BYTE)
, transaction_type_nm VARCHAR2(30 BYTE)
, workflow_object VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, workflow_request VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, workflow_return_cd VARCHAR2(30 BYTE) DEFAULT 'x' NOT NULL
, audit_action VARCHAR2(255 BYTE)
, last_update_user_logon_id VARCHAR2(12 BYTE)
, local_tm VARCHAR2(18 BYTE) NOT NULL
, local_time_zn_nm VARCHAR2(70 BYTE) DEFAULT 'GMT' NOT NULL
, local_daylight_in CHAR(1 BYTE) DEFAULT 'x' NOT NULL );
INSERT ALL
INTO wr_test
( message_id
, message_version
, create_tm
, message_status
, local_tm )
VALUES ( message_id
, 1
, create_tm
, '(Receive)'
, TO_CHAR(local_tm,'YYYYMMDD HH24:MI:SS') )
INTO wr_test
( message_id
, message_version
, create_tm
, message_status
, local_tm )
VALUES ( message_id
, 2
, create_tm
, 'Wait CLSB Ack'
, TO_CHAR
( local_tm + NUMTODSINTERVAL(DBMS_RANDOM.VALUE(0,2e5),'SECOND')
, 'YYYYMMDD HH24:MI:SS' ) )
SELECT ROWNUM AS message_id
, TO_CHAR(SYSDATE,'YYYYMMDD HH24:MI:SS') AS create_tm
, DATE '2000-01-01' + DBMS_RANDOM.VALUE(0,3) AS local_tm
FROM dual CONNECT BY ROWNUM < 100000;
WITH src AS
( SELECT message_id
, message_status
, message_version
, TO_DATE(SUBSTR(local_tm,1,17),'YYYYMMDD HH24:MI:SS') AS dt
, TO_DATE(SUBSTR(local_tm,1,8),'YYYYMMDD') AS dt_day
, TO_CHAR(TO_DATE(SUBSTR(local_tm,10,8),'HH24:MI:SS'),'SSSSS') AS dt_sec
FROM wr_test
WHERE message_status IN ('(Receive)','Wait CLSB Ack') )
SELECT dt_day + NUMTODSINTERVAL(period,'SECOND') AS dt
, NUMTODSINTERVAL(AVG(elapsed),'DAY') AS avg_elapsed
, NUMTODSINTERVAL(MIN(elapsed),'DAY') AS min_elapsed
, NUMTODSINTERVAL(MAX(elapsed),'DAY') AS max_elapsed
, COUNT(*)
FROM ( SELECT message_id
, message_status
, dt_day
, TRUNC(dt_sec/300)*300 AS period
, LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) AS ack_dt
, LEAD(dt) OVER (PARTITION BY message_id ORDER BY message_version) - dt AS elapsed
FROM src ) cal
WHERE cal.message_status = '(Receive)'
GROUP BY dt_day, period
ORDER BY 1;Replace "wr_test" with "tms_message_audit_log" in the WITH subquery to test on your data. -
How to compare two fields from the same table in the select statement
Hi, friends
I try to compare tow fields from the same table, but no result,
For example, this
data: cptotchek tyep i.
select count(*) into cptotchek
from aufk where erdat = aufk-idat2 .
The result is cptotchek = 0, but there are the records in aufk , where, aufk-erdat = aufk-idat2.
Please, help me, i don't use the loop statement for optimize my program.
RegardsHi ,
it will not return any value when you are using column of same table
such as Date Field , Because while Using Aggregate Function it will not check with self column
. For that you have to take data in one internal table and then you can work on it .
And if you are worried about Performance it will not affect , untill you are selecting only required data .
you can try this way .
data: cptotchek type i.
types : begin of w_aufk.
include structure aufk .
types : end of w_aufk .
data : it_aufk type standard table of w_aufk with header line .
select * into corresponding fields of table it_aufk
from aufk .
loop at it_aufk .
if it_aufk-erdat = it_aufk-idat2 .
write : / it_aufk-erdat , it_aufk-idat2 .
else .
delete it_aufk .
endif .
endloop.
Regards
Deepak. -
Hi people,
Since i guess this is a pretty common question, i did make a search in the forum and Google. I did not find the way to have 2 Headers in the same table.
I have a 4 pages long table. The same Header is quite useful in the first 2 pages but not in the last one and for design purposes (autoflow) is nice to have a long table not broken in smaller ones. I mean than in the last 2 pages i would need a different Header than the initial one.
Any idea?
THanks and cheers,
Sebastian>does your script [will] work on CS3 and Mac?
You mean the tagged text? (I see now I accidentally called it "INX" -- that's something else.) Yes, it's compatible all the way down to CS, but since it describes Javascript objects for CS4 only, the textual contents are of limited usefulness for CS3. However, you can inspect the document to see how to do the table trick.
Create a new, empty InDesign document, preferably of A4 size (as the tables are designed to fit). "Place" the tagged text document as usual -- ID should tell you it's placing tagged text. From then on, wait (and wait and wait some more -- it's about 800 pages) until ID has digested the massive chunk. Then you should get a lot of colorful pages! Click inside any table and, using Table Setup, inspect the Header/Footer tab field. If you deselect "Skip First Header" and "Skip Last Footer", you can see them on every page. Selecting these again hides the first ('continued') and last ('continued from last page') occurrences again. -
How to avoid that two or more people alter the same Sales Order same time
I'm looking for a way to avoid that two or more people altering the same Sales Order at the same time.
If someone has entered a Sales Order in the system and something needs to be adjust it can be done by two or more people at the same time. The problem is that when someone is saving these changes, the changes of another person, who is still working on the same order, get lost.
So what we need is an alert that someone is already using this order and that no other person can make any changes at that time. So the order needs to be blocked for altering for any other person at that time.
To avoid this I think you have to do something with the Stored Procedure. Or has someone a more simple and better solution.
I've already put this thread in the Business One forum and someone suggested to put it in the Business One SDK forum, as there isn't a solution in Business One itself.
So if someone can give me a direction for a solution I would be very pleased.
Best regards,
TimHi Tim,
The only thing that comes close to what you want in standard SBO is Data Ownership. However, this can't stop someone editing a document that is already being edited.
You can't use stored procedures to track which document is open because the SBO_SP_TransactionNotification proc (which is the only one that you are able to customise) is triggered when a document is updated or added (or cancelled or closed) and not when the document is actually being edited in the user-interface.
You could do this by writing an addon that uses the UI API to trap events in the sales order form. In theory, a sales order is being edited if the sales order form is in Update mode (ie in order for the form to be in Update mode, the user must have selected an existing document and changed the value of at least one field). You can trap the event of the user changing a value and then log the user and document in a table. When other users try to edit the same document, you could check the table and then prevent them changing values. When the first user clicks on the update button (or cancels the update or closes the form etc etc) you can remove the lock on the document. However, I have doubts as to how robust it would be. The problem with this kind of locking solution is that you sometimes get 'stranded' locks (eg user was editing a document when their workstation crashed) and the solution can end up being more troublesome than it is worth.
Kind Regards,
Owen -
Inserting a LONG to a BLOB in the same table
I have a table with a LONG column and would like to concatenate all existing columns into a new column in the same table and define it as a BLOB. I'm trying to figure out a way to do this. I tried the following and got error message
insert into cma_search_test
select obj_id,
line_id,
doc_nmbr,
supplier_part_num,
mnfctr,
mnfctr_part_nmbr,
line_desc,
ext_desc_txt,
vend_name,
cma_effect_dt,
cma_expir_dt,
last_updt_usr,
last_updt_tmsp,
obj_id||
line_id||
doc_nmbr||
supplier_part_num||
mnfctr||
mnfctr_part_nmbr||
line_desc||
to_lob(ext_desc_txt)||
vend_name||
cma_effect_dt||
cma_expir_dt||
last_updt_usr||
last_updt_tmsp "All_Columns"
from cma_search
to_lob(ext_desc_txt)||
ERROR at line 22:
ORA-00932: inconsistent datatypes
Any help would be appreciated.
Thanks,
TracyYou cannot concatenate a LONG field. You will have to use a procedure to accomplish what you want.
Use the DBMS_LOB package. -
Historical and transaction data in the same tables creates perf problems
Our Oracle based application is slow partly due to the fact that historical data are kept in the same table as transactional data. For example records about deceased patients, patients treated 5 years ago...etc, are kept in the one and only one patient table, which is needed to run the daily process of the hospital. So gradually all our major tables PATIENTS, CHARTS, NAMES, APPOINTMENTS have grown very large and since most of our SQL join all these tables at the same time, then all screens and reports run very slowly. I have introduced the idea that we should split all these tables in two: historical PATIENTS data, and CURRENT PATIENTS data...the same with all the others. A nice system would first search in the smaller transactional tables, which would run faster being smaller, and if no data found, then fallback to the historical tables. But this would require programming. From what I have read mateialized view could solve part of our problem. We could have views containing for example only one year worth of the data, and I guess any changes could be later replicated in the base table. What I dont know is what to do if we cannot find the patient in the matealized views ? Do I need to fallback to another SQL which will search in the initial base tables ? Anyway we can implement this without programming ? Tx.
Appointment table: 207,470
Visit table: 5,890,920
Patient table: 2,993,129
Chart table: 2,864,069
Patient names table: 3,938,118
SELECT
APPOI_OR_VISIT,
VISIT_SEQ,
PAT_SEQ,
INST_CODE,
INST_CODE_DISPL,
INST_DESC,
CLINIC_CODE,
CLINIC_CODE_DISPL,
CLINIC_DESC,
SPEC_CODE,
SPEC_CODE_DISPL,
SPEC_DESC,
VISIT_DATE,
VISIT_TIME,
VISIT_TIME_ARRIVAL,
APPTYPE_CODE,
SESSION_DOM_MODE,
PRESTYPE_CODE,
PRESTYPE_DOM_TYPE,
DIA_CODE,
VISIT_TIME_START_RESP,
VISIT_TIME_DISCHARGE,
APPOI_NB_DURATION,
VISIT_TX_REASON,
VISIT_TX_COMMENT,
EXTDOC_CODE,
VISIT_PN_REFPHYS_NAME,
PATYPE_CODE,
PAYRESP_CODE,
VISIT_IND_GROUP,
VISIT_PCODE,
VISIT_IND_COMPLETE,
VISIT_IND_ADMISSION,
VISIT_IND_CONFIDENTIALITY,
VISIT_DATE_ACCIDENT,
APPOI_SEQ,
BILLING_CODE,
VISIT_TX_DIAGNOSIS,
CST_CODE_1,
CST_CODE_2,
CST_CODE_3,
APPOI_DH_CRE,
APPOI_CODE_CRE_USER,
APPOI_DH_MOD,
APPOI_CODE_MOD_USER,
VISIT_CODE_CRE_USER,
VISIT_DH_CRE,
VISIT_UPDATED_COUNT,
VISIT_CODE_MOD_USER,
VISIT_DH_MOD,
APPOI_PAYRESP_CODE,
APPOI_DT_ACCIDENT,
PATIENT_LAST_NAME,
PATIENT_FIRST_NAME,
PATIENT_CONFIDENTIALITY,
PATIENT_CHART_EXT,
TO_NUMBER(SUBSTR(PATIENT_CHART_EXT, 1, INSTR(PATIENT_CHART_EXT, '|')-1)) AS PATIENT_CHART_NO,
PAT_IND_SPECIAL_RISK
FROM
SELECT
'VISIT' AS APPOI_OR_VISIT,
VISIT.VISIT_SEQ,
VISIT.PAT_SEQ,
INSTITUTION.INST_CODE,
INSTITUTION.INST_CODE_DISPL,
INSTITUTION.INST_DESC,
CLINIC.CLINIC_CODE,
CLINIC.CLINIC_CODE_DISPL,
CLINIC.CLINIC_DESC,
SPECIALTY.SPEC_CODE,
SPECIALTY.SPEC_CODE_DISPL,
SPECIALTY.SPEC_DESC,
VISIT.VISIT_DATE,
VISIT.VISIT_TIME,
VISIT.VISIT_TIME_ARRIVAL,
VISIT.APPTYPE_CODE,
VISIT.SESSION_DOM_MODE,
VISIT.PRESTYPE_CODE,
VISIT.PRESTYPE_DOM_TYPE,
VISIT.DIA_CODE,
VISIT.VISIT_TIME_START_RESP,
VISIT.VISIT_TIME_DISCHARGE,
VISIT.APPOI_NB_DURATION,
VISIT.VISIT_TX_REASON,
VISIT.VISIT_TX_COMMENT,
VISIT.EXTDOC_CODE,
VISIT.VISIT_PN_REFPHYS_NAME,
VISIT.PATYPE_CODE,
VISIT.PAYRESP_CODE,
VISIT.VISIT_IND_GROUP,
VISIT.VISIT_PCODE,
VISIT.VISIT_IND_COMPLETE,
VISIT.VISIT_IND_ADMISSION,
VISIT.VISIT_IND_CONFIDENTIALITY,
VISIT.VISIT_DATE_ACCIDENT,
VISIT.APPOI_SEQ,
VISIT.BILLING_CODE,
VISIT.VISIT_TX_DIAGNOSIS,
VISIT.CST_CODE_1,
VISIT.CST_CODE_2,
VISIT.CST_CODE_3,
VISIT.APPOI_DH_CRE,
VISIT.APPOI_CODE_CRE_USER,
VISIT.APPOI_DH_MOD,
VISIT.APPOI_CODE_MOD_USER,
VISIT.VISIT_CODE_CRE_USER,
VISIT.VISIT_DH_CRE,
VISIT.VISIT_UPDATED_COUNT,
VISIT.VISIT_CODE_MOD_USER,
VISIT.VISIT_DH_MOD,
NULL AS APPOI_PAYRESP_CODE,
TO_DATE(NULL) AS APPOI_DT_ACCIDENT,
NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(VISIT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
PATIENT.PAT_IND_SPECIAL_RISK
FROM
AS_T_VISITS VISIT,
CT_R_INSTITUTIONS INSTITUTION,
AS_T_CLINICS CLINIC,
CT_R_SPECIALITIES SPECIALTY,
PI_T_NAMES NAME,
PI_T_PATIENTS PATIENT,
PI_R_CONF_LEVELS CONFIDENTIALITY
WHERE
VISIT_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
VISIT_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
CLINIC.CLINIC_CODE = VISIT.CLINIC_CODE AND
SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
INSTITUTION.INST_CODE(+) = VISIT.INST_CODE AND
NAME.PAT_SEQ = VISIT.PAT_SEQ AND
NAME.NAMTYP_CODE = 1 AND
PATIENT.PAT_SEQ = VISIT.PAT_SEQ AND
CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE
UNION
SELECT
'APPOI' AS APPOI_OR_VISIT,
0 AS VISIT_SEQ,
NVL(APPOINTMENT_GROUP.PAT_SEQ, APPOINTMENT.PAT_SEQ) AS PAT_SEQ,
INSTITUTION.INST_CODE,
INSTITUTION.INST_CODE_DISPL,
INSTITUTION.INST_DESC,
CLINIC.CLINIC_CODE,
CLINIC.CLINIC_CODE_DISPL,
CLINIC.CLINIC_DESC,
SPECIALTY.SPEC_CODE,
SPECIALTY.SPEC_CODE_DISPL,
SPECIALTY.SPEC_DESC,
APPOINTMENT.SESSION_DATE AS VISIT_DATE,
APPOINTMENT.APPOI_TIME AS VISIT_TIME,
'' AS VISIT_TIME_ARRIVAL,
APPOINTMENT.APPTYPE_CODE,
APPOINTMENT.SESSION_DOM_MODE,
0 AS PRESTYPE_CODE,
'' AS PRESTYPE_DOM_TYPE,
0 AS DIA_CODE,
'' AS VISIT_TIME_START_RESP,
'' AS VISIT_TIME_DISCHARGE,
APPOINTMENT.APPOI_NB_DURATION,
APPOINTMENT.APPOI_TX_REASON AS VISIT_TX_REASON,
APPOINTMENT.APPOI_TX_COMMENT AS VISIT_TX_COMMENT,
APPOINTMENT.EXTDOC_CODE,
APPOINTMENT.APPOI_PN_REFPHYS_NAME AS VISIT_PN_REFPHYS_NAME,
APPOINTMENT_TYPE.PATYPE_CODE AS PATYPE_CODE,
0 AS PAYRESP_CODE,
DECODE(APPOINTMENT_GROUP.PAT_SEQ,NULL,0,1) AS VISIT_IND_GROUP,
'' AS VISIT_PCODE,
0 AS VISIT_IND_COMPLETE,
0 AS VISIT_IND_ADMISSION,
APPOINTMENT.APPOI_IND_CONFIDENTIALITY AS VISIT_IND_CONFIDENTIALITY,
TO_DATE(NULL) AS VISIT_DATE_ACCIDENT,
APPOINTMENT.APPOI_SEQ,
0 AS BILLING_CODE,
'' AS VISIT_TX_DIAGNOSIS,
0 AS CST_CODE_1,
0 AS CST_CODE_2,
0 AS CST_CODE_3,
APPOINTMENT.APPOI_DH_CRE AS APPOI_DH_CRE,
APPOINTMENT.APPOI_CODE_CRE_USER AS APPOI_CODE_CRE_USER,
APPOINTMENT.APPOI_DH_MOD AS APPOI_DH_MOD,
APPOINTMENT.APPOI_CODE_MOD_USER AS APPOI_CODE_MOD_USER,
'' AS VISIT_CODE_CRE_USER,
SYSDATE AS VISIT_DH_CRE,
0 AS VISIT_UPDATED_COUNT,
'' AS VISIT_CODE_MOD_USER,
SYSDATE AS VISIT_DH_MOD,
PAYRESP_CODE AS APPOI_PAYRESP_CODE,
APPOI_DT_ACCIDENT,
NAME.NAM_PN_NAM AS PATIENT_LAST_NAME,
NAME.NAM_PN_FNAM AS PATIENT_FIRST_NAME,
CONFIDENTIALITY.CONF_DESC AS PATIENT_CONFIDENTIALITY,
PI_SECURITY.F_GET_CHART_NUMBER_SCAN_CODE(APPOINTMENT.PAT_SEQ, 103 /*:pChartInstitutionID*/, 0) AS PATIENT_CHART_EXT,
PATIENT.PAT_IND_SPECIAL_RISK
FROM
AS_T_APPOINTMENTS APPOINTMENT,
AS_R_APPOINTMENT_TYPES APPOINTMENT_TYPE,
AS_T_CLINICS CLINIC,
CT_R_SPECIALITIES SPECIALTY,
CT_R_INSTITUTIONS INSTITUTION,
AS_T_APPOINTMENT_GROUPS APPOINTMENT_GROUP,
PI_T_PATIENTS PATIENT,
PI_R_CONF_LEVELS CONFIDENTIALITY,
PI_T_NAMES NAME,
AS_T_APPOINTMENT_SEQ_MAPPING SEQMAP
WHERE
SESSION_DATE >= TO_DATE('2004-04-01', 'YYYY-MM-DD') /*:P_VISIT_DATE_FROM*/ AND
SESSION_DATE <= TO_DATE('2004-04-02', 'YYYY-MM-DD') /*::P_VISIT_DATE_TO*/ AND
APPOINTMENT.APPOI_DOM_TYPE IN('A','AR') AND
CLINIC.CLINIC_CODE = APPOINTMENT.CLINIC_CODE AND
SPECIALTY.SPEC_CODE = CLINIC.SPEC_CODE AND
INSTITUTION.INST_CODE(+) = APPOINTMENT.INST_CODE AND
APPOINTMENT_GROUP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
APPOINTMENT_TYPE.APPTYPE_CODE (+) = APPOINTMENT.APPTYPE_CODE AND
NAME.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
NAME.NAMTYP_CODE = 1 AND
PATIENT.PAT_SEQ = NVL(APPOINTMENT.PAT_SEQ, APPOINTMENT_GROUP.PAT_SEQ) AND
CONFIDENTIALITY.CONF_CODE (+) = PATIENT.CONF_CODE AND
SEQMAP.APPOI_SEQ (+) = APPOINTMENT.APPOI_SEQ AND
SEQMAP.APPOI_SEQ IS NULL
ORDER BY
VISIT_DATE, VISIT_TIME, PATIENT_CHART_NO
Maybe you are looking for
-
Please let me know what I can do to get my Numbers (iWork 09) working properly again. Here is what is going on: Numbers in iWork 09 not working can't access Blank, Checklist and many other files within Numbers. I can open the program but only a few
-
Hi Friends, The present process is return sales , in which return sales order created with reference to sales order, Credit memo request created and Credit memo also created.But the problem is not getting print preview and print.Error message is Exci
-
Can I add a DVD-104 superdrive to Mac Pro
I want to add a DVD-104 superdrive to the second bay of my mac pro. Will it work? Do I have to move any of the jumpers on the drive. The first bay already has the 16x superdrive that came with the computer. Thanks, Gary
-
Hi, I'm facing some issues to populate dynamically DNS record of APs. The IPs addressing of APs are configured via DHCP servers (MS). The DHCP server is not configured to register automatically record against DNS (MS on the same server); as said by s
-
How can I disable 'Faces' in i-Photo?
How can I disable 'Faces' in i-Photo? This feature kicks in automatically after downloading new photos. I want to stop that. I don't want the feature. Thanks.