You still need to put a semicolon at the end of the set
line, surround your variable with ${}
and use the proper namespace.
Note that this will not execute the date_format()
function when the variable is defined. When you use the variable the SQL code will just be copied as-is. Think of it as more as a macro than as a variable.
Furthermore, Hive has multiple variable namespaces.
The 2 easiest options are either to be less verbose when you define your variable but to be more verbose when you use it (hiveconf namespace):
set today_date = date_format(date_sub(current_date, 1), 'YYYYMMdd');
select account from table where data_date = ${hiveconf:today_date};
or the other way round (hivevar namespace)
set hivevar:today_date = date_format(date_sub(current_date, 1), 'YYYYMMdd');
select account from table where data_date = ${today_date};