All Forums Database
DataHead 34 posts Joined 01/13
08 Jan 2013
Date variable to be applied to all date prompts - Teradata

Hi,
I have a long script Teradata SQL in SQL Assistant 13.11 that has about 20 places where a date is used, each time I run it, I need to change the dates manually & want to name the Date at the Start & add the variable name instead of the date to save work (& mistakes).
One thing though, the date appears in both 'YYYY-MM-DD' & also 'YYYY-MM-DD HH:MM:SS' Format.
I don't mind if I have to create & change 2 variables at the start - one for each Format type as it would still be better.
Thanks 

dnoeth 4628 posts Joined 11/04
13 Jan 2013

Check the SQLA help topic "Parameterized Queries".
In SQL Assistant you can define a parameter and use it multiple times within a request. 
select date '?dateparam', ...
from tab
where datecol between date '?dateparam' and date '?dateparam' + 3
Make shure Options - Query - "Allow use of Named Parameters in queries" is checked.
Dieter
 

Dieter

DataHead 34 posts Joined 01/13
14 Jan 2013

Thanks Dieter!!
 
Exactly what I needed, Thanks
How do I add thanks on this site for your help?
 
Peter
 

DataHead 34 posts Joined 01/13
14 Jan 2013

Just one more question Dieter,
 
I read the Parameterised Queries stuff in the Help menu, checked the checkbox etc.
I cant see a place where I actually name a variable a certain date?
Did you mean add a Select query at the start of my script?
I just want to add a variable called ?date for example & add that to every line that I need a date for.
 
Can you clarify for me?
 
Thanks
 
Peter

dnoeth 4628 posts Joined 11/04
15 Jan 2013

Hi Peter,
just you run the query (F5).
 An input dialog will pop up where you key in the date.
Dieter

Dieter

DataHead 34 posts Joined 01/13
15 Jan 2013

Thanks but I want to allocate a variable value somewhere in SQL Assistant - example "Date_Month" & then add "?Date_Month" wherever the script needs date input.
I have about 20 places that need the date which I need to update each month.
Is this possible?
Peter
 

You must sign in to leave a comment.