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 |
|
SQL_Stinger
Starting Member
40 Posts |
Posted - 2001-01-18 : 10:28:04
|
| I have stored procedures written to insert data into my tables. The first part of the script uses EXISTS to determine if there is a duplicate row already in the table and returns -1 if its a dupe:IF EXISTS(SELECT AllergenID FROM LstAllergensWHERE Allergen = @vchrAllergen AND ActiveFlag = 1)BEGIN Set @iReturnVal = -1 RETURNENDNow I want to return the negative value of the ID column (denoting the ID and the fact that the record existed).DECLARE @ID intSELECT @ID = AllergenID FROM LstAllergensWHERE Allergen = @vchrAllergen AND ActiveFlag = 1IF @ID IS NOT NULLBEGIN Set @iReturnVal = -1 * @ID RETURNENDOne of the developers is arguing that the SELECT requires more resources than the EXISTS. What do the gurus say?--------------------SQL Stinger |
|
|
|
|
|