Want to use date variable value in select query [message #605763] |
Tue, 14 January 2014 07:44 |
|
cplusplus1
Messages: 58 Registered: October 2012 Location: usa
|
Member |
|
|
I want to run a select query passing date value via declared variable.
I have created the below query and decalrade date var and trying to use.
declare v_Date1 date := to_date('01-JAN-2013', 'DD-Mon-YYYY');
begin
select 'MPEMP' as metric_code, sum(metric_amt) as METRIC_AMT from FACT_PIL_MET
INNER JOIN DT_METR
ON FACT_PIL_MET.METRIC_ID = DT_METR.METRIC_ID
INNER JOIN DT_CALENDAR_DAY
ON FACT_PIL_MET.METRIC_DAY_ID = DT_CALENDAR_DAY.CALENDAR_DAY_ID
where DT_METR.metric_code = 'MPEMP' and DT_CALENDAR_DAY.CALENDAR_DAY = v_Date1;
end;
I need to run almost 39 queries using same variable date value, for that reason trying to declare var and use it with in select queries with union all.
Thank you very much for the helpful info.
|
|
|
|
|
|
|
|
|
Re: Want to use date variable value in select query [message #605786 is a reply to message #605779] |
Tue, 14 January 2014 09:44 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
cplusplus1 wrote on Tue, 14 January 2014 14:43Yes, trying to use a date based variable within sql select query, this is my first time trying to use. What is the proper way to run the query getting variable date value in where condition.
Thanks a lot for the helpful info.
you realise that doesn't answer my question?
You can run sql queries from various different tools/languages, how you use variables in the query depends on the tool/language being used. Your example above is PL/SQL, if that's what you want then the variable is correct but you need to tell it what to do with the result.
|
|
|