21. juni 2004 - 10:03Der er
27 kommentarer og 1 løsning
Oprettelse af nye poster, baseret på eksisterende poster
Mit nye problem er nu at der i samme tabel findes en post med "owner_id" = x og "atype_idx" = 2 men der mangler en post magen til med samme "owner_id" = x og alle de andre udfyldte felter fra posten men "atype_idx" = 1. Så jeg skal have oprettet en ekstra post med alle de dataer fra "owner_id" = x, "atype_idx" = 2 til de poster som kun har en post med "owner_id" = x og "atype_idx" = 2.
I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
INSERT INTO tabel (owner_id,atype_idx,f1,f2,f3) SELECT owner_id,1,f1,f2,f3 FROM tabel t1 WHERE NOT EXISTS (SELECT * FROM tabel t2 WHERE t1.owner_id=t2.owner_id AND t2.atype_idx=1)
INSERT INTO tbladresser ([owner_id], [atype_idx],[zipcode] ,[city] ,[County])
SELECT [owner_id], 1,[zipcode] ,[city] ,[County] FROM tbladresser WHERE tbladresser.[atype_idx] = 2 AND [owner_id] NOT IN (SELECT T.Owner_ID FROM tbladresser T WHERE [atype_idx] = 1 )
Not as it is! The table and field names need altering. INSERT INTO tbladresser ([owner_id], [atype_idx],[zipcode] ,[city] ,[County]) SELECT owner_id, 1,[zipcode] ,[city] ,[County] FROM tbladresser t1 WHERE NOT EXISTS (SELECT * FROM tbladresser t2 WHERE t1.owner_id=t2.owner_id AND t2.atype_idx=1)
I dont understand what the problem is with NULL values! If a field is NULL already then the field must accept NULL values! Are you saying that it doesnt?
Jeg har nu inkluderet de felter som ikke kan være "NULL" så det er løst. Men til gængeld er der et felt "address_id" som skal have det samme nr. + 1 som er i den post som skaber tvillingen
When i try too run this, it complains about a "incorrect syntax near ')' ???
INSERT INTO crm5.address (address_id, owner_id, atype_idx, zipcode, city, county, updatedCount, updated_associate_id, updated, registered_associate_id,) SELECT address_id + 1 AS Expr2, owner_id, 1 AS Expr1, zipcode, city, county, updatedCount, updated_associate_id, updated, registered_associate_id, registered FROM crm5.address WHERE (atype_idx = 2) AND (owner_id NOT IN (SELECT T.Owner_ID FROM crm5.address T WHERE atype_idx = 1))
The error "Cannot insert dublicate key row in object 'address' with unique index 'IDXAddrId'" indicates that you aretrying to create a record where the index 'IDXAddrId' already exists. One or more fields in the table are used to make the index and it is these which you are trying to duplicate.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.