传递密钥,插入数据库 [英] Passing a key, inserting into database

查看:56
本文介绍了传递密钥,插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个耐心的表格,上面有一个链接.单击链接后,我将Patientkey传递到对话框.该对话框有一个名为激活患者"的按钮.单击该按钮后,患者键&输入日期被插入到患者访问表中.在我的SQL语句中,我使用患者键检查重复项.

选择@dupCount = Count(PatientKey)
来自PatientAccess
其中PatientKey = @PatientKey
如果@dupCount> 1转到DUPLICATE_ERROR

当我第一次单击激活患者"时,它会激活患者.
当我第二次单击激活患者"时,它将在表中创建一个重复的患者键.当我第三次单击它时,它最终抛出了重复的错误.我不知道是否使用患者钥匙来检查它是否是最佳选择.

问题:在对话框中,传递了PatientKey之后,我是否有办法获取PatientAccessKey,以便可以使用它来检查重复项?最好的方法是什么?欢迎所有帮助!谢谢!

PatientAccess表
PatientAccessKey(PK)身份字段
PatientKey
EntryDate

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

推荐答案

让我们仔细研究一下逻辑.

通过1

Lets go through the logic.

Pass 1

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



@dupCount = 0

如果@dupCount> 1转到DUPLICATE_ERROR

条件为假.

通过2



@dupCount = 0

If @dupCount > 1 GoTo DUPLICATE_ERROR

Condition is false.

Pass 2

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



@dupCount = 1

如果@dupCount> 1转到DUPLICATE_ERROR

条件为假,因为1不大于1

通过3



@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

如果@dupCount> 1转到DUPLICATE_ERROR

条件为真,因为两个大于1.

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

考虑使用大于0的条件,或大于或等于1的条件.

霍根



@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


这篇关于传递密钥,插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆