• When writing a procedure I always assume that some of the data will be bad or non-existant. Thus, I almost always set up defaults so SOMETHING is returned to the client app. Something like this

    DECLARE UserID AS INT

    SELECT

    ROW_NUMBER() OVER (PARTITION BY UserID ORDER BY UserName) AS RowNum

    ,ISNULL(NULLIF(UserId,''),0 AS UserID

    ,ISNULL(NULLIF(UserName,''), as UserName

    FROM

    Users

    WHERE

    UserID = @user-id

    So if nothing is returned I still get at least one row although it may be empty:

    RowNum UserID UserName

    1 0 [blank]