MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 28th, 2004, 03:26 PM
wlit wlit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 12 wlit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Question on Trigger Insert-Phone number?

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

Reply With Quote
  #2  
Old April 28th, 2004, 03:52 PM
wlit wlit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 12 wlit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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]%')

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Question on Trigger Insert-Phone number?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway