Excel - SQL Query - Parameters check for null input

bell282

New Member
Joined
Jun 2, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I am using excel 365.
I have a drop down box as an input parameter to a query. I need to be able to check is that input parameter is null.

State: <drop down of available states>

Report showing city, zip code and other data

For the drop down box, I am using the following query:
Select null as [State]
UNION
Select distinct State from tbl_states

Then the query to display the report:

What I am using in the sql statement is:
Select columns
from table_State s
where ( s.State = ? or ? is null )

This is not working.

I know in tsql, it would be written:
declare @State varchar(50)
set @State= 'Ohio'
-- set @State = null
select distinct state
from tbl_States s
where ( (@State is null) or (s.State = @State) )

Any suggestions on how to correct my query?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Thanks! Yes, isnull does work when I run the query in Microsoft sql server management studio but not excel. I think the 'null' value that I am trying to return is being converted is an empty string.

stumped...
 
Upvote 0
Other items I have tried:
Select columns
from table
where column = ? or isnull(?, '') = ''

I have both parameters set to the same input parameter

With this approach, I receive an error message 'string date; right truncation'
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,594
Members
452,656
Latest member
earth

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