SQL Variables | Databend

-- Create a table with sales data

CREATE TABLE sales_data (region TEXT, sales_amount INT, month TEXT) AS

SELECT 'North', 5000, 'January' UNION ALL

SELECT 'South', 3000, 'January';

select * from sales_data;

-- Set variables for the table name and column name

SET VARIABLE table_name = 'sales_data';

SET VARIABLE column_name = 'sales_amount';

-- Use IDENTIFIER to dynamically reference the table and column in the query

SELECT region, IDENTIFIER($column_name)

FROM IDENTIFIER($table_name)

WHERE IDENTIFIER($column_name) > 4000;