SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 PLS I NEED HELP WITH VALIDATIONS
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Tijesuni
Starting Member

Nigeria
4 Posts

Posted - 03/15/2013 :  13:38:09  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
6062 Posts

Posted - 03/15/2013 :  15:53:38  Show Profile  Reply with Quote
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

Nigeria
4 Posts

Posted - 03/16/2013 :  04:20:28  Show Profile  Reply with Quote
thanks alot TG it worked...GOD BLESS YOU!!!
This has been giving problems for a while
Thanks so much
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000