Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Locate item in a table
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pinto
Aged Yak Warrior

United Kingdom
590 Posts

Posted - 08/02/2006 :  05:12:43  Show Profile  Reply with Quote
I have a sql table containing names of departments. Is there a way after a user has typed a department in a textbox on a web page I can search for it in the sql table and if it isn't there then add it. I am using asp.net for the web page.

chiragkhabaria
Flowing Fount of Yak Knowledge

India
1907 Posts

Posted - 08/02/2006 :  05:19:33  Show Profile  Visit chiragkhabaria's Homepage  Send chiragkhabaria a Yahoo! Message  Reply with Quote
Create the stored procedure which will look somthing like this ..


Create Proc Ins_Department(@pDept Varchar(1000))
As 
Begin 
--First Check if the Department exists or not if not then insert.. 
 If Not Exists (Select DName From Department Where DName = @pDept)
Begin 
  Insert Department(DName)
  Select @pDept
End

End 


Call this proc from your front end..

Chirag
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 08/02/2006 :  05:29:30  Show Profile  Reply with Quote
Or place the not exists in the WHERE clause

Create Proc Ins_Department(@pDept Varchar(1000))
As 
Begin 
  --First Check if the Department exists or not if not then insert.. 
  Insert Department(DName)
  Select @pDept
  Where Not Exists (Select DName From Department Where DName = @pDept)
End



KH

Go to Top of Page

Pinto
Aged Yak Warrior

United Kingdom
590 Posts

Posted - 08/02/2006 :  05:44:25  Show Profile  Reply with Quote
Thank you. I have got that to work perfectly !
Go to Top of Page
  Previous Topic Topic Next 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.07 seconds. Powered By: Snitz Forums 2000