How can I pass a variable to a sql statement inside a function
I would like to create a function that returns the rowcount from a table based on the value I pass in to the function. Like this: CREATE OR REPLACE FUNCTION get_my_rowcount(tblname VARCHAR(50),id INT) RETURN INT AS BEGIN RETURN ( CASE WHEN tblname = 'table1' THEN (SELECT COUNT(*) FROM table1 WHERE my_id = id) WHEN tblname = 'table2' THEN (SELECT COUNT(*) FROM table2 WHERE my_id = id) WHEN tblname = 'table3' THEN (SELECT COUNT (*) FROM table3 WHERE my_id = id) ELSE 0 END ); END; When I run this I get the following error: ROLLBACK: column "id" does not exist
Sign up
Already have an account? Login
Welcome to the Rocket Forum!
Please log in or register:
Employee Login | Registration Member Login | RegistrationEnter your E-mail address. We'll send you an e-mail with instructions to reset your password.