SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SP: if exisit, then .... execute

    hello,
    i have this code below that inserts phone numbers into a table. HOwever i would like to know how i could add a search to the script to check to see if the number exists before entering it into the table ?

    thanks

    Code:
    AS INSERT INTO [1wday_com_sql].[dbo].[sms_phonebook] 
    ([username],
    [Phone_number],
    [Nickname]) 
    select 
    @username_1,
    @Phone_number_1,
    @Nickname_1
    
    where @Phone_number_1 is not null and @phone_number_1 <>  '23480' and @phone_number_1 <> 
    (select @Phone_number_1 from sms_phonebook where username = @username_1)
    union all .... BLAH BLAH BLAH

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,248
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    don't

    declare a UNIQUE constraint and let the database do the work

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •