Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select and return PK value
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01673328
Message ID:
01673332
Views:
39
>Hi,
>
>My stored procedure receives a value of an equipment ID (optional; that is, an empty string could be passed).
>In the SP I want to find if such ID exists and if so, set the value of the equipment PK.
>How do I test if the value of @EquipPk is NULL (record not found) on one line with the SELECT?
>
>
>IF @EquipmentID <> '' and  @EquipPk = (SELECT EQUIP_PK FROM EQ_FILE where ID_NUMBER = @EquipmentID)
>	BEGIN
>              -- return error
>       END
>
>
>TIA

Why does it have to be one line?
if COALESCE(@EquipmentId,'') !=''
   begin
   select @Pk = equip_pk from dbo.eq_file where Id_Number = @EquipmentId;
   if @Pk==null
             begin
                 raieserror ...
                 return 
             end
     end
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform