Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 PLS I NEED HELP WITH VALIDATIONS

Author  Topic 

Tijesuni
Starting Member

4 Posts

Posted - 2013-03-15 : 13:38:09
I have this table

MANAGEMENT.PAYMENTS

PaymentID
PatientID
PaymentDate
PaymentMethod
CC_Num
CC_Name
Check_Num
AdvancePayment
FinalPayment
PaymentStatus


Pls how to i perform the following validation

1)CC_Num and CC_Name will record the credit card number and name respectively.This details should be entered if payment is made by credit card Else they should be NULL
2)Check_Num should record the check number. This detail should be entered if payments is made by check else it should be NULL

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-03-15 : 15:53:38
you could add a check constraint on the table. Something like this:

alter table payments
add constraint CK_PaymentMethod check
(
(PaymentMethod = 'Credit Card' and CC_Num is not null and CC_Name is not null and Check_Num is null)
OR
(PaymentMethod = 'Check' and CC_Num is null and CC_Name is null and Check_Num is not null)
)


Be One with the Optimizer
TG
Go to Top of Page

Tijesuni
Starting Member

4 Posts

Posted - 2013-03-16 : 04:20:28
thanks alot TG it worked...GOD BLESS YOU!!!
This has been giving problems for a while
Thanks so much
Go to Top of Page
   

- Advertisement -