This is a discussion on stored procedure and if exists within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, In my stored procedure I would like to do something like : IF EXISTS ( SELECT WebId FROM ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, In my stored procedure I would like to do something like : IF EXISTS ( SELECT WebId FROM Webs WHERE FormatDateId = @FormatDateId ) BEGIN SELECT WebId FROM Webs WHERE FormatDateId = @FormatDateId SET @RetVal = -1 END Is there a nicer way to do this, so that we don't have to do the request twice ? Regards |
| |||
| You could use @@ROWCOUNT to see if the query returns a row: SELECT WebId FROM Webs WHERE FormatDateId = @FormatDateId set @rows = @@ROWCOUNT if @rows = 1 set @RetVal = -1 -- we found one row else .... -- do something else here Simon |
| Thread Tools | |
| Display Modes | |
|
|