Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a patient form that has a link on it. When the link is clicked, I pass the patientkey to a dialog. The dialog has a button named "Activate Patient." When the button is clicked the patientkey & entry date are being inserted into the patient access table. In my SQL statement I am checking for duplicates, using the patient key.

Select @dupCount = Count(PatientKey)
From PatientAccess
Where PatientKey = @PatientKey
If @dupCount > 1 GoTo DUPLICATE_ERROR

When I click the "Activate Patient" the first time, it activates the patient.
When I click the "Activate Patient" the second time it creates a duplicate patientkey into the table. When I click it a third time it finally throws up a duplicate error. I don't know if using the patient key to check it is the best option or not.

Question: In the dialog, after the passing the patientKey, is there a way for me to obtain the PatientAccessKey so I can use that to check duplicates against? What would be the best way? All help is welcomed! Thanks!

PatientAccess Table
PatientAccessKey (PK) Identity field
PatientKey
EntryDate
Posted

1 solution

Lets go through the logic.

Pass 1

SQL
Select @dupCount = Count(PatientKey)
From PatientAccess
Where PatientKey = @PatientKey


@dupCount = 0

If @dupCount > 1 GoTo DUPLICATE_ERROR

Condition is false.

Pass 2

SQL
Select @dupCount = Count(PatientKey)
From PatientAccess
Where PatientKey = @PatientKey


@dupCount = 1

If @dupCount > 1 GoTo DUPLICATE_ERROR

Condition is false, as 1 is not Greater than 1

Pass 3

SQL
Select @dupCount = Count(PatientKey)
From PatientAccess
Where PatientKey = @PatientKey


@dupCount = 2

If @dupCount > 1 GoTo DUPLICATE_ERROR

Condition is true because two is greater than 1.

-------------------------------------------------------------------------------

Consider using Greater than 0 for your condition, or Greater than or equal to 1.

Hogan
 
Share this answer
 
Comments
ahlaj77 24-Jul-12 10:41am    
Such a simple solution that I did not catch myself. Thank you VERY much for your help! It's working now.
snorkie 24-Jul-12 10:46am    
Glad I could help. Good luck your app and have fun!

Hogan

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900