Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select and return PK value
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01673328
Message ID:
01673332
Vues:
40
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform