Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Issue Case Expression in store procedure of mysql

I am facing problem in store procedure of mysql. mainly i am facing CASE problem Those change the result.But i want choice result according call Like if i want table order according to id or name or class. So i implement CASE Expression. But not find result properly

store procedure bellow

CREATE PROCEDURE StudentTablePagination
(

      IN Class NVARCHAR(50) ,
      IN Name NVARCHAR(50),
      IN StartRecord INT,
      IN PageSize INT,
      IN SortColumn NVARCHAR(20),
      IN SortOrder NVARCHAR(4)
)
BEGIN
  IF SortOrder = 'ASC' 
  Then
     SELECT  id from lakes where name like CONCAT('%',Name,'%') AND  class like 
     CONCAT('%',Class,'%')
     ORDER BY  (
       CASE SortColumn
       WHEN 'name' THEN lakes.name
       WHEN 'state' THEN lakes.state
       ELSE id END
    ) Asc 
    LIMIT StartRecord, PageSize;

 ELSEIF SortOrder = 'DESC' 
 Then
    SELECT  id from lakes where name like CONCAT('%',Name,'%') AND  class like 
    CONCAT('%',Class,'%')
    ORDER BY  (
      CASE SortColumn
      WHEN 'name' THEN lakes.name
      WHEN 'state' THEN lakes.state
      ELSE id END
    )  DESC LIMIT StartRecord , PageSize;
 END IF;
END

Call:

CALL StudentTablePagination('','', 0,10,'id','asc')

and Result:

id
10
100
1000

But Result Require:

id
1
2
3
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!