Excel SQL Connection if parameter is blank

Dmcnich15

New Member
Joined
Feb 14, 2015
Messages
8
Hello-

Here is my setup. I have a data connection in Excel that runs a SQL query. There are 2 parameters, year and month, that point to cells in excel. I would like if month is left blank to pull everything for the year.

For instance

If year = 2017 and month = 12 pull december of 2017
If year = 2017 and the cell for month is blank pull all of 2017


Im not sure if this is possible but if so what would be the best way to use it? I tried adding a case statement in my SQL for isnull but that isnt translating to excel
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Something like this should work:
SELECT fields FROM table WHERE YEAR(datefield) = [year param] AND ([month param] = 0 or [month cell] IS NULL or MONTH(datefield) = [month param]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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