Click here to Skip to main content
Sign Up to vote bad
good
See more: C#SQL
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


1 solution

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
  Permalink  
Comments
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

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Mahesh Bailwal 413
1 Sergey Alexandrovich Kryukov 384
2 Maciej Los 200
3 Aarti Meswania 193
4 Rohan Leuva 165
0 Sergey Alexandrovich Kryukov 9,417
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 24 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid