SQL statement VBA : need to ignore blank values

albertan

Board Regular
Joined
Nov 16, 2014
Messages
68
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

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