Compare two records column by column in same table
Hi All,
I have an address table with ID as the PK but there can be more than one ID. I need to take the latest address record and first see if that same ID has a previous address record and if so, compare each column to see if the data has changed. I only need to compare the latest record with the next latest record.
I cannot figure this out at all. I can of course use the MAX function to get the latest address records but do not know how I can pull the next latest address record that matches the ID and compare each column.
Sample table:
ID street city state zip effective_date
1 123 main chicago IL 60111 3-7-2012
2 34 N 13th new york NY 18374 3-7-2012
3 15 N main Dallas TX 47389 3-7-2012
1 89 N main chicago IL 60111 1-5-2012
1 16 East St columbus OH 47382 12-10-2011
2 34 N 13th new york NY 18374 10-7-2011
2 15 S Elm new york NY 18374 09-1-2011
3 15 N main Dallas TX 47389 10-4-2011
SO...in the table above using today as the latest record date, based of my criteria I would only want to pull record ID 1 and 2 since the next most recent record for those IDs have had at least one of their address data change. ID 3 has exactly the same address data so I would not consider that in my criteria.
Can i do this with SQL only or will i need to create a procedure or function?
Any help is appreciated
Ben
Ben C wrote:
Hi All,
I have an address table with ID as the PK but there can be more than one ID. You mean there can be more than one row with tha same ID, right? (There can be more than one ID, also.)
I need to take the latest address record and first see if that same ID has a previous address record and if so, compare each column to see if the data has changed. I only need to compare the latest record with the next latest record.
... Sample table:Whenever you have a problem, please post CREATE TABLE and INSERT statements for the sample data, and the exact results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.
Can i do this with SQL only or will i need to create a procedure or function?You don't need PL/SQL, if I understand your requirements. You can do something like this:
WITH got_analytics AS
SELECT id, street, city, state, zip, effective_date
, COUNT (*) OVER ( PARTITION BY id ) AS cnt
, ROW_NUMBER () OVER ( PARTITION BY id
ORDER BY effective_date DESC
) AS r_num
FROM table_x
-- WHERE ... -- If you need any filtering, put it here
SELECT id, street, city, state, zip, effective_date
FROM got_analytics
WHERE cnt > 1
AND r_num <= 2
ORDER BY id
, effective_date
;This will show the most recent 2 rows for each id that has 2 (or more) rows.
You can modify it to only include ids where there was some change in street, city, state or zip between those 2 rows.
WITH got_analytics AS
SELECT id, street, city, state, zip, effective_date
, COUNT (*) OVER ( PARTITION BY id ) AS cnt
, ROW_NUMBER () OVER ( PARTITION BY id
ORDER BY effective_date DESC
) AS r_num
FROM table_x
-- WHERE ... -- If you need any filtering, put it here
, got_unique_cnts AS
SELECT id, street, city, state, zip, effective_date
, COUNT (DISTINCT '~' || street) OVER (PARTITION BY id) AS street_cnt
, COUNT (DISTINCT '~' || city) OVER (PARTITION BY id) AS city_cnt
, COUNT (DISTINCT '~' || state) OVER (PARTITION BY id) AS state_cnt
, COUNT (DISTINCT '~' || zip) OVER (PARTITION BY id) AS zip_cnt
FROM got_analytics
WHERE cnt > 1
AND r_num <= 2
SELECT id, street, city, state, zip, effective_date
FROM got_unique_cnts
WHERE street_cnt > 1
OR city_cnt > 1
OR state_cnt > 1
OR zip_cnt > 1
ORDER BY id
, effective_date
;This assumes that street, city, state and zip are all VARCHAR2s. If any of those columns is NULL on one row, and not NULL on the other row for that ID, that counts as a difference.
Edited by: Frank Kulash on Mar 7, 2012 3:37 PM
Edited by: Frank Kulash on Mar 7, 2012 3:41 PM
Similar Messages
-
Compare two records within a view
Hi,
I wonder if it is possible to compare two or more records within a view, and how to do it.
Thanks in advance.M. Comi wrote:
I wanted to compare two records of the view and see if they are the same or not...
My data are as follows:
Soglia Ingresso_CL_PF 10 10
Downgrade MDP 3 2102 2101
I want to check if the "downgrade" records have the same values for the second and the third column, and in this case replace the values on the second record.
But I did it with a select on the same fields of the original tables, plus two fields obtained with lag function...
I don't know if it is clear or not, the important is that I got what I wanted.Sorry, it's not clear.
Are you still having a problem? If so:
(1) Please describe the problem.
(2) What results do you want to see from the sample data you posted?
(3) Is the second column of
Downgrade MDP 3 2102 2101'Downgrade', 'MDP', 3, 2102, 2101, some combination, or NULL? When posting data, the most helpful thing is to post INSERT (or CREATE TABLE AS ...) statements. The second-best thing is to post formatted data. Type {code} before and after sections where spacing is important, and post column headers. -
How to compare two records of table
Hi all,
How to compare new record with all existing records in table.
In my application i have status column ,which contains the information about
the record is new or old record .
thank you/*does record 1 have friend*/
WITH t AS
(SELECT 1 AS Id, 'a' AS NAME, 'type1' AS Col
FROM Dual
UNION ALL
SELECT 2 AS Id, 'a' AS NAME, 'type1' AS Col
FROM Dual
UNION ALL
SELECT 3 AS Id, 'a' AS NAME, 'type2' AS Col FROM Dual)
SELECT count(*) as YesNo
FROM t T1
WHERE T1.Id = 1
AND (T1.Name, T1.Col) IN (SELECT T2.Name, T2.Col FROM T t2 where t2.ID != T1.Id);
1
/*does record 3 have friend*/
WITH t AS
(SELECT 1 AS Id, 'a' AS NAME, 'type1' AS Col
FROM Dual
UNION ALL
SELECT 2 AS Id, 'a' AS NAME, 'type1' AS Col
FROM Dual
UNION ALL
SELECT 3 AS Id, 'a' AS NAME, 'type2' AS Col FROM Dual)
SELECT count(*) as YesNo
FROM t T1
WHERE T1.Id = 3
AND (T1.Name, T1.Col) IN (SELECT T2.Name, T2.Col FROM T t2 where t2.ID != T1.Id);
0
*/ -
Comparing two records from different tables error.
Hi folks!
I have this PL/SQL Block.
I want to compare the only one record from both tables to see if the content of them are equal or not, but I don't want to specified column by column to do that.
Any idea?
Thanks a lot in advanced,
Abdel E. Miranda S.
Panama
declare
cursor c_aems_prueba is
select nombre, direccion, telefono, limite, seq
from aems_prueba;
cursor c_aems_testing is
select nombre, direccion, telefono, limite, seq
from aems_testing;
vc_aems_prueba c_aems_prueba%rowtype;
vc_aems_testing c_aems_testing%rowtype;
vt_aems_prueba aems_prueba%rowtype;
vt_aems_testing aems_testing%rowtype;
begin
insert into aems_prueba
values('ABDEL MIRANDA', 'PAITILLA', '215-3411', 1000, 1);
insert into aems_testing
values('ABDEL MIRANDA', 'PAITILLA', '215-3411', 1000, 1);
commit;
open c_aems_prueba;
fetch c_aems_prueba into vt_aems_prueba;
open c_aems_prueba;
fetch c_aems_prueba into vt_aems_testing;
if vt_aems_prueba = vt_aems_prueba
then
dbms_output.put_line('son iguales las variables, si funciona la comparacion de dos estructuras');
else
dbms_output.put_line('no son iguales las variables, no funciona la comparacion de dos estructuras');
end if;
close c_aems_prueba;
close c_aems_testing;
end;Satyaki De,
Java is involving because an Outsourcing new project. The outsourcing company is developing the new application using JSF which invoke an interface java method [depending of the operation: select, update, insert] and them invoke the PLSQL API to precess tha operation.
In the case I already wrote here, the issue is this:
The user search for a specific data using the interface. The java method send a request for these operation through the API. the PLSQL process the request and return a beam, with all the column the user look for.
The user see the information in the application windows. Assuming the user wants to change some data, he modify just one field [lets say telephone number] and press the update button. The application process the request using a different method, which invoke a different function within the PLSQL API.
Once the information is returning to the API, I must know if at least one field change its value. So I was thinking to get the beam with the data before it was changed and compare it with the beam with the changing data.
If current_beam = new_beam
then
update
else
no change to process
end if;
Any idea. -
Report with multiple COUNT columns with counts from same table
I am new to discoverer so I am a bit lost.
I am working to create a report to show usage data from the eBusiness Knowledge Base. I have the query written in SQL using subqueries that is in the format:
Solution Number | Soultion Title | Solution Views | Positive Feedback | Negative Feedback
12345 ___________ Title ________ 345 ____________ 98 _______________ 34
The 'Views', 'Positive' and 'Negative' entries are stored in the same table so i am doing a count where setid=setid and usedtype=VS, then counting where usedtype=PF and usedtype=NF
In discoverer I can get the solution number, title and ONE of the totals but I can't seem to figure out how to get a COUNT for three different things from the same table in columns on the same row.
When I go to edit sheet -> select items once I select the COUNT option for the UsedType column in the table CS_KB_SET_USED_HISTS I can't select it again. I also have found now way to add a column based on an entered query.
If anyone could help it would be much appreciated.
Thanks
Edited by: Toolman21 on Dec 2, 2010 2:17 PM
added ______ to correct spacing.Hi,
You can separate the column by using a case or decode.
for example create 2 calculations:
case
when usedtype='PF'
then <you original column> --- the one contain them both
else 0
end
case
when usedtype='NF'
then <you original column> --- the one contain them both
else 0
end
after that you can create the count aggregation over those.
Tamir -
Render a column based on other column value in the same table
JDev 11.1.1.6.0
This may be a silly question but I am stuck
I need to conditionally render a column say A. Condition is like if the value in the other column B of same table is equal to F. I should render column A only when this condition is satisfied. I have tried the following code:
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146"
rendered="#{row.PhoneNumber1ResponseFlag eq 'F'}">
<af:outputText value="#{row.PhoneNumber1}"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80" rendered="true">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
The data shown in the table for column PhoneNumber1ResponseFlag is F. Still my condition is not working.Timo was saying that it is not possible to render the column in some situations and not in anothers, you will always have to render the column.
The best way to do this is instead of showing a column with the text ' ', show something meaningfull to the user. This is a DataWarehouse advice to you and may be usefull since you're using ADF in a area that uses DataWarehouse..
So the code could be something like this (based on Timo's code):
<af:column sortProperty="PhoneNumber1"
sortable="false"
headerText="#{bindings.A.hints.PhoneNumber1.label}"
id="c146">
<af:outputText value="#{row.PhoneNumber1ResponseFlag eq 'False.' ? row.PhoneNumber1 : 'No value applied.'"
id="ot130"/>
</af:column>
<af:column sortProperty="PhoneNumber1ResponseFlag"
sortable="false"
headerText="#{bindings.B.hints.PhoneNumber1ResponseFlag.label}"
id="c80">
<af:outputText value="#{row.PhoneNumber1ResponseFlag}"
id="ot129"/>
</af:column>
Hope that helps,
Frederico. -
Two records getting inserted with the same timestamp...
hi all,
I am trying to submit a form . Now whenever I click submit before I insert any
data sent in that form I make a check (SELECT stmt. to see if that record can
be inserted ...few business validations..) and if the check is successful I then
proceed for the necessary insert into a table the Primary key for which is a running
Oracle sequence.
But if I click on the Submit button twice in close succession I have observed
may be 1 in 1000 attempts I am able to submit two records with the same time stamp
for the date of insertion . We are using Oracle 8 with weblogic 5.1. And I don't
think ORACLE's date precision is beyond seconds.
So any suggestion ..what is the best way to handle such things : one can be
to place the same business validation check just before the ending brace of the
method , or secondly sucmit the form thru javascript and don't submit it twice
even if the user clicks the submit button twice... any suggestion which u can
give .. are welcome.
thnx in advance
sajan
Is the pkey a timestamp or an Oracle sequence? The latter will always work,
since no two requests to a sequence can get the same value (rollover
excluded). If you must use timestamp, then you must auto-retry the insert
if the first attempt fails. Oracle does have higher precision than seconds,
but I can remember the exact precision ... I am pretty sure it works out to
at least two or three digits though.
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com
Tangosol Server: Enabling enterprise application customization
"Sajan Parihar" <[email protected]> wrote in message
news:[email protected]...
>
> hi all,
> I am trying to submit a form . Now whenever I click submit before I
insert any
> data sent in that form I make a check (SELECT stmt. to see if that record
can
> be inserted ...few business validations..) and if the check is successful
I then
> proceed for the necessary insert into a table the Primary key for which is
a running
> Oracle sequence.
> But if I click on the Submit button twice in close succession I have
observed
> may be 1 in 1000 attempts I am able to submit two records with the same
time stamp
> for the date of insertion . We are using Oracle 8 with weblogic 5.1. And I
don't
> think ORACLE's date precision is beyond seconds.
> So any suggestion ..what is the best way to handle such things : one
can be
> to place the same business validation check just before the ending brace
of the
> method , or secondly sucmit the form thru javascript and don't submit it
twice
> even if the user clicks the submit button twice... any suggestion which u
can
> give .. are welcome.
>
> thnx in advance
> sajan
-
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. -
UPDATE value in column with value in SAME TABLE
Hi all,
Here's my issue...
I have a table which records all incidents for a person.
The table looks something like this:
tbl_connect(person_Id NUMBer,
OLD_ID VARCHAR2(24),
CASE_NUMBER VARCHAR2(10),
CASE_TYPE VARCHAR2(10),
PERSON_ROLE VARCHAR2(30),
INCIDENT_TYPE VARCHAR2(40));
The table is populated from a source table with all fields except person_id. Person_id is a sequence number that gets generated if the person comitting the incident is a NEW PERSON to our system. OLD_Id is the unique identifier between the source table and tbl_connect to identify a person.
The problem: If an existing person commits a new incident, a new record will be inserted into tbl_connect without PERSON_ID. Since the person already is in the database the person_id already exists in tbl_connect for that person. I now need to UPDATE person_id column with the person_id that already exists for this person. How can i achieve this.
Ive been trying all sorts of update queries but nothing seems to work. ANy help will be appreciated. Thanks in advance.Frank,
Thanks for the speedy reply. Here is a sample table.
I know it's a bit confusing. The data that is being dumped into this table is information from a old system. The OLD_ID is in here because it is the relationship between this table and the old table. PERSON_ID is new to this system to identify a person uniquely. That is why i need them both in this table for right now.
So say my tbl_connect got populated with new info from the old table. As you can see, old_id=567A has comitted another incident. Since he already exists in tbl_connect, now i need to update person_id with the value of 1. Does that make sense now????? If old_id did not exist, all i would do is insert a new row and set person_id to the next sequence number.
TBL_CONNECT
PERSON_ID OLD_ID CASE_NUMBER CASE_TYPE
1 567A 12345 IR
1 567A 15236 MV
567A 98547 IR<--newly inserted record of same person -
Calculating a count of rows where value matches another column value in the same table
Hi,
I'm struggling to do something in DAX that seems to me should be super easy (coming from a SQL world)!
That is to count all rows in column 1 where the value matches the current value for column 1?
E.g something like this:
[Col2]=Count of rows in [Col1] where value = this.[Col1]
Where the results are as in the table below:
Col1, Col2
A, 2
A, 2
B, 1
Anyone?
Martin Laukkanen
Nearbaseline blog - nearbaseline.com/blog
Bulk Edit and other Apps - nearbaseline.com/appsThanks, that's perfect!
I knew it had to be something so simple, but after spending over an hour banging my head against those exact functions I couldn't get anything working!
Martin Laukkanen
Nearbaseline blog - nearbaseline.com/blog
Bulk Edit and other Apps - nearbaseline.com/apps -
Compare two strings and verify they have same alphabets
If i have two strings....s and t. I want to return whether s contains every letter in t. For example, "abcd" contains all the letters in "bbdc", since every letter in the second string appears in teh first.
thanxIf i have two strings....s and t. I want to return
whether s contains every letter in t. For example,
"abcd" contains all the letters in "bbdc", since every
letter in the second string appears in teh first.This will do the job in s.length()*t.length() steps.
// Indicates whether s contains every letter in t.
boolean allCharsContainedIn(String s, String t) {
int len = t.length();
for (int i = 0; i < len; i++) {
if (s.indexOf(t.charAt(i) == -1)
return false;
return true;
}Søren -
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 helpHello 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. -
How to compare two separate PDF files with certain fields identical?
Does anyone know of a way that I could compare two separate PDF files containing the same information in certain locations? Please keep in mind that they contain different information as well. I know that it could be done with importing it to excel and running VBA to format the information to be similar and use formulas to validate information is correct, but this needs to be done very quickly with multiple files through out the day. One way to explain what type of PDF file this is, is think of excel: Column A and J contain the same information but B:I contain different information. Any help or suggestions is greatly appreciated.
This unfortunately was never answered but we found a different solution rather than comparing PDF's.
-
Combine values from two records in one query
Hello.
Is it possible to combine two record - only one column value?
With one query we get these results:
A____B____C____D____E_______F_______G______H
+++++++++++++++++++++++++++++++++++++++++
28___84___P___16____________1____02.06.09___1
28___84___p___8_____________1____02.06.09___1
28___84___S___16____________1____02.06.09___1
28___84___T___12____________1____02.06.09___1
28___84___1___137___________1____02.06.09___1
28___84___5___18___66,42____1____02.06.09____1
28___84___6___14____________1____02.06.09___1
28___84___8___17___214,2____1____02.06.09___1
If there is a record with column C value 'p', then column value 'D' should be added to record with C value 'P' and 'S': result should be like this:
No 'p' record and values (D column) for 'P' and 'S' should be a summed by 8 from record 'p'.
A____B____C____D____E_______F_______G______H
+++++++++++++++++++++++++++++++++++++++++
28___84___P___24____________1____02.06.09___1
28___84___S___24____________1____02.06.09___1
28___84___T___12____________1____02.06.09___1
28___84___1___137___________1____02.06.09___1
28___84___5___18___66,42____1____02.06.09____1
28___84___6___14____________1____02.06.09___1
28___84___8___17___214,2____1____02.06.09___1
And this should be restricted to column A value.
Any idea?
Thanks.
Edited by: DejanH on Jun 2, 2009 11:39 AMOK, that's a messy requirement, here's one for 'p' but no 'P' (and 't' but no 'T'), and you can expand that for others yourself.
WITH test_data AS (
SELECT 28 A, 84 B, 'p' C, 8 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, 'S' C, 16 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, 'T' C, 12 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, '1' C, 137 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, '5' C, 18 D, 66.42 E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, '6' C, 14 D, NULL E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL UNION ALL
SELECT 28 A, 84 B, '8' C, 17 D, 214.2 E, 1 F, TO_DATE('02.06.09','DD.MM.YY') G, 1 H FROM DUAL)
-- end test data
SELECT td1.A, td1.B, td1.C,
CASE WHEN td1.C IN ('P', 'S') THEN NVL(td1.D,0) + NVL(td2.D, 0) ELSE td1.D END D,
TO_CHAR(td1.E * 100, 'fm99990,09') E, td1.F, td1.G, td1.H
FROM test_data td1
LEFT JOIN (
SELECT A, SUM(D) D
FROM test_data
WHERE C= 'p'
GROUP BY A) td2
ON (td1.A = td2.A)
WHERE C != 'p'
GROUP BY td1.A, td1.B, td1.C, CASE WHEN td1.C IN ('P', 'S') THEN NVL(td1.D,0) + NVL(td2.D, 0) ELSE td1.D END, TO_CHAR(td1.E * 100, 'fm99990,09'), td1.F, td1.G, td1.H
UNION
SELECT td1.A, td1.B, UPPER(td1.C) C,
SUM(td1.D) D,
TO_CHAR(td1.E * 100, 'fm99990,09') E, td1.F, td1.G, td1.H
FROM test_data td1
WHERE td1.C in ('p', 't')
GROUP BY td1.A, td1.B, UPPER(td1.C),TO_CHAR(td1.E * 100, 'fm99990,09'), td1.F, td1.G, td1.H
ORDER BY 1
A B C D E F G H
28 84 1 137 1 02-JUN-09 1
28 84 5 18 66,42 1 02-JUN-09 1
28 84 6 14 1 02-JUN-09 1
28 84 8 17 214,20 1 02-JUN-09 1
28 84 P 8 1 02-JUN-09 1
28 84 S 24 1 02-JUN-09 1
28 84 T 12 1 02-JUN-09 1
7 rows selected. -
Trigger to Update in the same table.
Hi,
I would like to create a trigger that when we insert into table ALL_CAPACITY_SNS_CELL1 it updates column Action on teh same table,if teher is an update, it will update the same table , column ACTION.
This is what I have attempted but seems to be technically wrong.
<pre>
create table ALL_CAPACITY_SNS_CELL1
( A varchar2,
action char(2),
date_executed date);
create or replace
TRIGGER ALL_CAPACITY_HISTORY_TRACKING
AFTER INSERT OR DELETE OR UPDATE ON ALL_CAPACITY_SNS_CELL1 FOR EACH ROW
DECLARE
v_operation VARCHAR2(10) := NULL;
BEGIN
IF INSERTING THEN
v_operation := 'I';
ELSIF UPDATING THEN
v_operation := 'U';
ELSE
v_operation := 'D';
END IF;
IF INSERTING
UPDATE ALL_CAPACITY_SNS_CELL1
SET ACTION =v_operation,
DATE_EXECUTED =sysdate ;
ELSIF UPDATING THEN
UPDATE ALL_CAPACITY_SNS_CELL1
SET ACTION =v_operation,
DATE_EXECUTED =sysdate ;
END IF;
END;
</pre>CrackerJack wrote:
But above query made all ACTION nul...so we shoudl after insert or update trigger right?Obviously it is not working. You modified my code the way it does not make sense.
IF INSERTING
THEN
:NEW.ACTION := 'I';
IF UPDATING
THEN
:NEW.ACTION := 'U';
ELSE
:NEW.ACTION := 'X';
END IF;The code above checks if trigger fired on INSERT (IF INSERTING). In THEN branch of that IF you check if trigger fired on UPDATE. It makes no sense. Now, if you would use my trigger:
SQL> create table ALL_CAPACITY_SNS_CELL1
2 ( A varchar2(1),
3 action char(2),
4 date_executed date);
Table created.
SQL> create or replace
2 TRIGGER ALL_CAPACITY_HISTORY_TRACKING
3 BEFORE INSERT
4 OR UPDATE
5 ON ALL_CAPACITY_SNS_CELL1
6 FOR EACH ROW
7 BEGIN
8 IF INSERTING
9 THEN
10 :NEW.ACTION := 'I';
11 ELSE
12 :NEW.ACTION := 'U';
13 END IF;
14 :NEW.DATE_EXECUTED := sysdate ;
15 END;
16 /
Trigger created.
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('A')
2 /
1 row created.
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('B')
2 /
1 row created.
SQL> alter session set nls_date_format='mm/dd/yyyy hh24:mi:ss'
2 /
Session altered.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
A I 05/13/2009 08:56:02
B I 05/13/2009 08:56:09
SQL> update ALL_CAPACITY_SNS_CELL1
2 set a = 'X'
3 where a = 'B'
4 /
1 row updated.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
A I 05/13/2009 08:56:02
X U 05/13/2009 08:57:05
SQL> update ALL_CAPACITY_SNS_CELL1
2 set a = 'Y'
3 /
2 rows updated.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
Y U 05/13/2009 08:57:21
Y U 05/13/2009 08:57:21
SQL> insert into ALL_CAPACITY_SNS_CELL1(a) values('C')
2 /
1 row created.
SQL> select * from ALL_CAPACITY_SNS_CELL1
2 /
A AC DATE_EXECUTED
Y U 05/13/2009 08:57:21
Y U 05/13/2009 08:57:21
C I 05/13/2009 08:57:53
SQL> SY.
Maybe you are looking for
-
not printing full 6x4 when set to 6x4 leaving at least 1/2" at the ends un printed this is bad any answers to solve this problem please have tried looking on hp but cannot find a answeer to the problem.
-
When my ATV runs hot it seems like the picture has a slight shake to it when looking at the letters on the menu items. Has anyone else seen this effect? I am running it on a 120" projection screen and yes Im using the proper video format. Feedbak on
-
Allowing respondents to print as PDF
Do you have any idea when we might have this ability? We want to purchase the product but this is really something that we want to see.
-
My iPad setting icon is missing how can I retrieve it?
I cannot find the setting icon of my iPad. I've tried everything, the push the sleep button and the other button thingy on the same time for 10-15 secs... It doesn't work at all. What should I do?
-
Workaround for Firefox browser not recognized by SLL search engine?
Attempting to add Google SLL (https://addons.mozilla.org/en-US/firefox/addon/google-ssl-243978/?src=ss) to Firefox (35.0.1 Mozilla FIrefox for Ubuntu canonical - 1.0) fails with the error message "Sorry, you need a Mozilla-based browser (such as Fire