Date variable to be applied to all date prompts - Teradata

Database
Enthusiast

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 

5 REPLIES
Junior Contributor

Re: Date variable to be applied to all date prompts - Teradata

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

Enthusiast

Re: Date variable to be applied to all date prompts - Teradata

Thanks Dieter!!

Exactly what I needed, Thanks

How do I add thanks on this site for your help?

Peter

Enthusiast

Re: Date variable to be applied to all date prompts - Teradata

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

Junior Contributor

Re: Date variable to be applied to all date prompts - Teradata

Hi Peter,

just you run the query (F5).

 An input dialog will pop up where you key in the date.

Dieter

Enthusiast

Re: Date variable to be applied to all date prompts - Teradata

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