dd_UPR00100_SEL_cbo

This is a stored procedure that returns EmployID and the Full Name (both last name and first name first), and is sorted by a parameter.

Using a variable to sort a SQL statement is an unusual technique, the statement is work studying just for that.

 

IF EXISTS (SELECT name
       FROM   sysobjects
       WHERE  name = N'dd_UPR00100_SEL_cbo'
       AND    type = 'P')
    DROP PROCEDURE dd_UPR00100_SEL_cbo
GO
 
CREATE PROCEDURE dd_UPR00100_SEL_cbo
-- dd_UPR00100_SEL_cbo 3
 
@sort int --1 = employid
          --2 = frstname
          --3 = lastname
 
AS
     
SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
 
select employid,
    rtrim(frstname) + ' ' + rtrim(lastname) as FullName1,
    rtrim(lastname) + ', ' + rtrim(frstname) as FullName2
    from upr00100 e
    order by case when @sort = 1 then employid
        when @sort = 2 then frstname + lastname
        else lastname + frstname end
     
 
go
 
grant exec on dd_UPR00100_SEL_cbo to public
 
--sp_sps

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences