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.
| Author |
Topic |
|
azamsharp
Posting Yak Master
201 Posts |
Posted - 2005-09-09 : 16:27:46
|
| I wrote this very bad SPROC which returns 0 if not found and the id when its found. How can I improve on this. CREATE PROCEDURE [usp_GetForumID] @CourseID int, @ForumID int OUTPUT ASIF NOT EXISTS ( SELECT ForumID FROM tblMyTable WHERE CourseID = @CourseID ) BEGIN SET @ForumID = 0END ELSE SET @ForumID = ( SELECT ForumID FROm tblMyTable WHERE CourseID = @CourseID ) GOMohammad Azam www.azamsharp.net |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-09 : 16:34:37
|
| Just set @ForumID = 0 prior to the SELECT. SET @ForumID = 0SELECT @ForumID = ForumID FROm tblMyTable WHERE CourseID = @CourseIDWhen no rows satisfy the query, then @ForumID will be 0.Tara |
 |
|
|
|
|
|