Question: I can't get a select combo box to open reports upon the click of a button. Here's what I have. What do you suggest? It's opening the report Inventory only when nothing is clicked but I can't get it to open the other reports.

```
Private Sub Run_Inventory_Report_Macro_Click()
Dim strSortBy As String

strSortBy = Nz(Me.cmb_InventorySort.Value, "")

Select Case strSortBy
Case ""
    DoCmd.OpenReport "Inventory", acViewPreview
Case "Provider ID"
    DoCmd.OpenReport "Inventory-Provider Number", acViewPreview
Case "Provider Last Name"
    DoCmd.OpenReport "Inventory-Provider Last Name", acViewPreview
Case "Inventory Type"
    DoCmd.OpenReport "Inventory-Inventory Type", acViewPreview
Case "Corporate Receipt Date"
    DoCmd.OpenReport "Inventory-Corporate Receipt Date", acViewPreview
Case "PODM Receipt Date"
    DoCmd.OpenReport "Inventory-PODM Receipt Date", acViewPreview
End Select

End Sub

```

Answer: 
It's pretty common to load variables into a CTE and reference the CTE in your SELECT statement:

```
WITH variables AS
(
    SELECT 5 as thresholdmin, 10 as thresholdmax
)
SELECT CASE WHEN 6 BETWEEN thresholdmin and thresholdmax then 1 ELSE 0 END as thresholdCheck 
FROM variables

```

You can just cross join that CTE into your other tables (or derived tables) and make the same reference much like the Volatile table answer above, but without the bloat of actual storage.

An example using the sys\_calendar:

```
WITH variables AS
(
    SELECT DATE '2016-01-01' as minDate, DATE '2016-01-31' as maxDate
)
SELECT cal.calendar_date 
FROM sys_calendar.calendar cal, variables
WHERE cal.calendar_date BETWEEN variables.minDate and variables.maxDate
ORDER BY cal.calendar_date

```

This is a nice solution because it will work on any RDBMS that supports CTEs (so everything except for mysql --UPDATED-- mysql 8.0+ now supports CTEs!).
You can't create variables in a typical Teradata sql script. Instead create a volatile table and store the value of your "variable" in the table. Then query the value from your volatile table when you need to use it. It would look something like this:

```
CREATE VOLATILE TABLE MyVariable
(
VariableValue int
) Primary index (VariableValue)
ON COMMIT PRESERVE ROWS;

INSERT INTO MyVariable(VariableValue)
VALUES (5);

SELECT COALESCE(
    CASE WHEN X >= VariableValue THEN 'A' ELSE NULL END
    ,CASE WHEN Y >= VariableValue THEN 'B' ELSE NULL END
) 
FROM YourTable, MyVariable;

```

If you decide you want to put your logic inside a stored procedure, then you can `DECLARE` variables.

Here are the actual variable declaration rules:
<http://info.teradata.com/htmlpubs/DB_TTU_15_00/index.html#page/SQL_Reference/B035_1148_015K/ch08.143.035.html#ww593657>