|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to write a trigger on insert. However, on the phone field I want to limited the area code that is allow to enter. The code below doesn't seem working. Any suggestion?
create trigger trg_add_cust on customer for insert as declare @cust_last varchar(20), @cust_first varchar(20), @cust_phone varchar(15), @cust_add varchar(30), @cust_city varchar(20), @cust_state varchar(2), @cust_zip numeric(5,0), select @cust_last=(select cust_last from inserted) select @cust_last=(select cust_last from inserted) select @cust_phone=(select cust_phone from inserted) select @cust_add=(select cust_add from inserted) select @cust_city=(select cust_city from inserted) select @cust_state=(select cust_state from inserted) select @cust_zip=(select cust_zip from inserted) IF NOT EXISTS (SELECT 1 FROM CUSTOMER WHERE @cust_phone = '410%' OR @cust_phone ='301%') Begin Print 'Area code enter must be either 410 or 301' Print 'Please re-enter' ROLLBACK TRANSACTION END |
|
#2
|
|||
|
|||
|
I think I got it, does this look ok?
IF NOT EXISTS (SELECT 1 FROM CUSTOMER WHERE @cust_phone like '[410]%' OR @cust_phone like '[443]%') |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Question on Trigger Insert-Phone number? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|