>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
>
> 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