sql please help me please

erikayperry

New Member
Joined
Aug 12, 2015
Messages
11
Hello,

I have the SQl script below. It currently runs off me entering the date. However, I now want to be able to enter a number in the parameter box instead. For instance, If I enter 123 I want to see all the times 123 came along with what came 2 days before and 1 day after.

Example: 2/1/2016 ----123
1/31/2016----234
1/30/2016----456
2/2/2016-----555
This is my script below.

PARAMETERS [Enter Date:] DateTime, [Enter YourNumber:] IEEEDouble;
SELECT "YourTable" AS SourceTable, YourDate, YourNumber
FROM YourTable
WHERE YourDate BETWEEN [Enter Date:]-1 AND [Enter Date:]+1
UNION ALL
SELECT "Cash4Table", YourDate, YourNumber
FROM Cash4Table
WHERE YourDate BETWEEN [Enter Date:]-1 AND [Enter Date:]+1
UNION ALL
SELECT "Fantasy5Table", yourDate, YourNumber
FROM Fantasy5Table
WHERE YourDate BETWEEN [Enter Date:]-1 AND [Enter Date:]+1
UNION ALL
SELECT "GAFiveTable", YourDate, YourNumber
FROM GAFiveTable
WHERE YourDate BETWEEN [Enter Date:]-1 AND [Enter Date:]+1
UNION ALL SELECT "MoonPhaseTable", YourDate, YourNumber
FROM MoonPhaseTable
WHERE YourDate BETWEEN [Enter Date:]-4 AND [Enter Date:]+1
ORDER BY SourceTable, YourDate;
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try out the Query with the following changes:
Code:
PARAMETERS [Enter Date:] DateTime, [Enter YourNumber:] IEEEDouble;
SELECT "YourTable" AS SourceTable, YourDate, YourNumber
FROM YourTable
WHERE YourDate BETWEEN ([Enter Date:]-1 AND [Enter Date:]+1) AND (YourNumber = [Enter YourNumber])
UNION ALL
SELECT "Cash4Table", YourDate, YourNumber
FROM Cash4Table
WHERE YourDate BETWEEN ([Enter Date:]-1 AND [Enter Date:]+1) AND (YourNumber = [Enter YourNumber])
UNION ALL
SELECT "Fantasy5Table", yourDate, YourNumber
FROM Fantasy5Table
WHERE YourDate BETWEEN ([Enter Date:]-1 AND [Enter Date:]+1) AND (YourNumber = [Enter YourNumber])
UNION ALL
SELECT "GAFiveTable", YourDate, YourNumber
FROM GAFiveTable
WHERE YourDate BETWEEN ([Enter Date:]-1 AND [Enter Date:]+1) AND (YourNumber = [Enter YourNumber])
UNION ALL SELECT "MoonPhaseTable", YourDate, YourNumber
FROM MoonPhaseTable
WHERE YourDate BETWEEN ([Enter Date:]-1 AND [Enter Date:]+1) AND (YourNumber = [Enter YourNumber])
ORDER BY SourceTable, YourDate;
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,126
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top