SQL statement VBA : need to ignore blank values

albertan

Board Regular
Joined
Nov 16, 2014
Messages
66
Office Version
  1. 365
Hello,

I have a VBA with an SQL statement. I need to ignore any values that are blank

Below is portion of VBA:

"SELECT * FROM Data.dbo.Contract_Summary_Workbook as w WHERE w.""ProjectNo"" " & _
"like '" & Lists.Range("C4").Value & "%' or w.""ProjectNo"" like '" & Lists.Range("C3").Value & "%' or w.""ProjectNo"" not like '" & Lists.Range("C9").Value & "%'" _
)

in C9 I have blank cell with no content, in C4 and C3 I have project numbers.
If there will be blank content in C3 the data still gives me all table dump (for all projects).

Is there a way for me to exclude any input variables that have blanks?

I don't really know if there's a way for me to loop through input values in SQL statement.

Thanks,
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
maybe check for len(range("c9"))
if it is zero, use SQL ".. ProjectNo Is Not Null
otherwise stay with what you have
 
Upvote 0
maybe check for len(range("c9"))
if it is zero, use SQL ".. ProjectNo Is Not Null
otherwise stay with what you have


For now I decided to fill blank input rows with "N/A" and included statement in SQL so that it picks it with 'N/A%' and it doesn't, so it works
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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