Toad World® Forums

How do you define a variable in toad?

Wish to create the ability to slice data base by start and stop dates. How do you define the variables to do this?
I wish to be prompted for enter of dates start and stop to pull time slices from data as:

SELECT * from ap_checks where (a_check_date >= :Start_Date) and
from ap_checks where (a_check_date <= :End_Date)

Not sure how to provide correct syntex. Also, with variable bind how the IN, OUT,INOUT or RETRUN apply? Need to convey <= and >= with respect to read between dates. How do you tell Toad that?
Tks,

Depends how you are trying to accomplish this. If you are writing a script or stored procedure in SQL, you can use the DECLARE sytax for your SQL flavor. If you want Toad to pop up a dialog where you can enter a value for a named variable in your script, use the :variablename notation. For example:

SELECT * from myTable where myDate = :datevariable
1 Like

When using the Query Builder a lot of the work is done for you. Here I have a simple query to return PART_NUMBER and DATE_CREATION. By clicking the Where for DATE_CREATION the default is to use a prompted variable (of the same name) - notice the colon character in the criteria. This could be left as-is, or the name of the variable could be changed.

Thank you. I am sorry for my lack of Toad skill at this point. Can you please advise if Query Builder is part of Toad Data Point and if so what menu options help one reach it?

I tried the following code in the editor and it appears to work :

SELECT * from ap_checks where (a_check_date) >= :Start_Date ) and (a_check_date <= :End_Date)

OOPS S/B:

SELECT * from ap_checks where (a_check_date >= :Start_Date ) and (a_check_date <= :End_Date)

Hi,

Query Bilder is a module that helps users who are not so skilled with SQL. You can click your query easily there with all variable and other conditions.
There are two easy ways how to open your QB.