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 24 Jul '12 - 4:15
ahlaj77146

## Solution 1

Lets go through the logic.

Pass 1

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

@dupCount = 0

If @dupCount > 1 GoTo DUPLICATE_ERROR

Condition is false.

Pass 2

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

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
Programmer in the Making - 24 Jul '12 - 10:41
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:46
Glad I could help. Good luck your app and have fun! Hogan