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
 General SQL Server Forums
 New to SQL Server Programming
 Need Help with condition on field

Author  Topic 

sanlen
Starting Member

29 Posts

Posted - 2008-10-23 : 21:50:12
Hi All,

I am trying to create the table as the below code. With this table there is a condition which applied to the field payment_method. i.e: if the payment_method is the CREDIT CARD then credit_card_no, card_holder_name, card_expired_date cannot be left blank, else those field can be NULL.

Could you please advise how can i apply the above conditions to the payment_method?

Thanks you very much for any advise you may give me.


CREATE TABLE Payments
(
payment_id INT IDENTITY(1,1),
payment_amount MONEY,
payment_date DATETIME,
project_id VARCHAR(10),
payment_method_id VARCHAR(10),
payment_method VARCHAR(30),
credit_card_no VARCHAR(30),
card_holder_name VARCHAR(30),
card_expired_date DATETIME,

CONSTRAINT ck_payment_amount CHECK(payment_amount > 0),
CONSTRAINT pk_paymentid PRIMARY KEY(payment_id),
CONSTRAINT fk_pro_id FOREIGN KEY(project_id) REFERENCES Project(project_id),
CONSTRAINT fk_payment_method FOREIGN KEY(payment_method_id) REFERENCES PaymentMethods(payment_method_id)
)

Best Regard,
SANLEN

raky
Aged Yak Warrior

767 Posts

Posted - 2008-10-24 : 00:48:51
if the payment_method is the CREDIT CARD then credit_card_no, card_holder_name, card_expired_date cannot be left blank, else those field can be NULL -- set this condition in insert sp which is used to insert data into this table. Create table such that credit_card_no, card_holder_name, card_expired_date can allow null values....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-24 : 01:23:28
or make a trigger to enforce this condition check for insert & updates.
Go to Top of Page
   

- Advertisement -