-2
CREATE DEFINER=`newuser`@`localhost` PROCEDURE `spSelectAllCustomers`(
IN customRole VARCHAR(30))
BEGIN
IF customRole IS NULL THEN
SELECT * FROM  db.Customers AS c;
ELSE
SELECT customRole FROM db.Customers AS c; 
END IF;
END

call db.spSelectAllCustomers('UPPER(c.CustomerName)');

SELECT UPPER(c.Name) FROM Customers AS c; i want to run this query but i want to pass UPPER(c.Name) as a parameter like SELECT customRole FROM Customers AS c;

I'm trying to send UPPER(c.Name) as argument but compiler is treating it as varchar and returning 'UPPER(c.Name)' for every row of the column 'Name'

Charlieface
  • 52,284
  • 6
  • 19
  • 43
Nil
  • 11
  • 2
  • You want to provide not a value but a code part as a parameter. You need in dynamic SQL for this. – Akina Aug 17 '22 at 11:57
  • Please add sample data and desired outcome as text. – P.Salmon Aug 17 '22 at 12:59
  • SELECT UPPER(c.Name) FROM Customers AS c; i want to run this query but i want to pass UPPER(c.Name) as a parameter like SELECT customRole FROM Customers AS c; – Nil Aug 18 '22 at 13:49

1 Answers1

-2

we cannot pass like below

EXECUTE spSelectAllCustomers, customRole=UPPER(c.Name) 

It should be some string input like this

EXECUTE spSelectAllCustomers 'your value'
Vasanth R
  • 172
  • 1
  • 1
  • 14
  • Double quotes are generally not acceptable as a string delimiter. Here you would need to assign the result of UPPER to a variable - so you approach is both logically incorrect and confusing to the inexperienced. – SMor Aug 17 '22 at 11:34