Avatar billede carstensm Nybegynder
27. april 2002 - 14:05 Der er 3 kommentarer og
2 løsninger

Validering ved INSERT og UPDATE

Ved indsættelse af data skal en dato ligge mellem to andre datoer som er defineret i en anden tabel.

Hvordan kan jeg tjekke dette med en INSERT sql-sætning, evt. med en stored procedure?

I øjeblikket tjekker jeg med en SELECT forespørgsel før min INSERT, men det er lidt dobbeltarbejde.

Jeg har forsøgt med "Validation Rule", men kan ikke få det til at virke.

MVH
Carsten
Avatar billede terry Ekspert
27. april 2002 - 14:25 #1
Are you entering your data through an Access form or ASP pages or something else?

You would normally validate BEFORE inserting! Why waist  time inserting if you find that the data is incorrect?

If you are inserting your data through an Access form then you can check the date interval in the BEFORE UPDATE event for the form.
Avatar billede carstensm Nybegynder
27. april 2002 - 14:31 #2
I'm using Access from a Java program via ODBC.
I'd rather not use VB or any other non-protable stuff in order to keep my database-options open in the future.
Avatar billede terry Ekspert
27. april 2002 - 14:38 #3
carstensm> You say that you already make a select before your insert, what is wrong with doing it that way? If you dont do it there then you would have to do it in a stored procedure anyway, how else will you know if it is valid?
Avatar billede carstensm Nybegynder
27. april 2002 - 15:20 #4
I was hoping that "Validation Rule" would be able to accept queries or the like. Another posibility was that Access supported advanced sql(can't remember what it's called) with IF...ELSE, as I believe MS-SQL does.

But maybe I set my hopes too high, so I'll just carry on as I used to.
Avatar billede terry Ekspert
27. april 2002 - 15:50 #5
IF ...ELSE is not supported in an Access (jet) database, although it more than likley is if you use the MSDE database (Access 2000 and later) The MSDE database is actually a "cut down" version of SQL Server so it supports stored procedures and triggers. I have NEVER used this database although I have used SQL SERVER which supports much more than Access. I still do NOT see how you can get away with having to make a select on the table containing the dates.

The problem with using the validation rule is that the record is not yet written to the database so you cant refer to the field containing the date from the validation rule property.

I think your current method is fine :o)
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester