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
 Locate item in a table

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2006-08-02 : 05:12:43
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
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-02 : 05:19:33
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)

17689 Posts

Posted - 2006-08-02 : 05:29:30
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

590 Posts

Posted - 2006-08-02 : 05:44:25
Thank you. I have got that to work perfectly !
Go to Top of Page
   

- Advertisement -