how to do a contains statement in sql?

Dark0Prince

Active Member
Joined
Feb 17, 2016
Messages
433
Code:
Select 
MLB8.PROG_REPORT_ACCT_NUM_AND_PRACCT, 
DCGI.Date_Listed, 
DB.INITIAL_BALANCE, 
DS.Last_Payment, 
LV.Amt_Paid_On_Acct, 
DB.Principal_Balance, 
MLB7.INVENT_INVEN2
From
Clnt_General CG
Inner Join
Dbtr_Clnt_Generl_Inf DCGI on CG.Client_Num1=DCGI.Client
Inner Join
Dbtr_Status DS on DCGI.Account_Num1=DS.Account_Num1
Inner Join
Dbtr_Balances DB on DCGI.Account_Num1=DB.Account_Num1
Inner Join 
Debtor_Master_Logic_Blocks7 MLB7 on DCGI.Account_Num1=MLB7.Account_Num1
Inner Join 
Debtor_Master_Logic_Blocks8 MLB8 on DCGI.Account_Num1=MLB8.Account_Num1
Inner Join 
Letter_Variables LV on DCGI.Account_Num1=LV.Account_Num1
Where
CG.Client_Num1=?
And 
DCGI.Date_Listed>?

This is my current code and I'm trying to add a where filter that says: when 4 5 6 7 10 15 20 21 25 35 36 37 40 45 46 57 58 65 75 86 87 91 92 99 numbers are not contained in DS.Cancel_Reason
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try:
Code:
Where Ds.Cancel_Reason Not In (4,5,6,7,10,15,20,21,25,35,36,37,40,45,46,57,58,65,75,86,87,91,92,99)
 
Upvote 0
Code:
Select 
MLB8.PROG_REPORT_ACCT_NUM_AND_PRACCT, 
DCGI.Date_Listed, 
DB.INITIAL_BALANCE, 
DS.Cancel_Reason,
DS.Last_Payment, 
LV.Amt_Paid_On_Acct, 
DB.Principal_Balance, 
MLB7.INVENT_INVEN2
From
Clnt_General CG
Inner Join
Dbtr_Clnt_Generl_Inf DCGI on CG.Client_Num1=DCGI.Client
Inner Join
Dbtr_Status DS on DCGI.Account_Num1=DS.Account_Num1
Inner Join
Dbtr_Balances DB on DCGI.Account_Num1=DB.Account_Num1
Inner Join 
Debtor_Master_Logic_Blocks7 MLB7 on DCGI.Account_Num1=MLB7.Account_Num1
Inner Join 
Debtor_Master_Logic_Blocks8 MLB8 on DCGI.Account_Num1=MLB8.Account_Num1
Inner Join 
Letter_Variables LV on DCGI.Account_Num1=LV.Account_Num1
Where
CG.Client_Num1=?
And 
DCGI.Date_Listed>?
And
Where DS.Cancel_Reason Not In (4,5,6,7,10,15,20,21,25,35,36,37,40,45,46,57,58,65,75,86,87,91,92,99)

I added it but I get this long error code "..A term expected, beginning with one of the following: identifier, constant, aggregate, %ALPHAUP, %EXACT, %MVR, %SQLSTRING, %SQLUPPER, ..."
 
Upvote 0
You add it to your existing WHERE clause (you cannot have two WHERE clauses like that).
(Sorry if I wasn't clear on that, I shouldn't have assumed that you are an experienced SQL code writer).

So your total WHERE clause would look like:
Code:
Where
CG.Client_Num1=?
And 
DCGI.Date_Listed>?
And
DS.Cancel_Reason Not In (4,5,6,7,10,15,20,21,25,35,36,37,40,45,46,57,58,65,75,86,87,91,92,99)
(except I hope you really have something other "?" at the end of the first two conditions, because those are not valid SQL statements).
 
Upvote 0
LOL i knew not to do that but didn't notice it there. Also the ? work as sql statements because they prompt for the parameters when you refresh or you can set them to associate with cells in excel.
 
Upvote 0
Also the ? work as sql statements because they prompt for the parameters when you refresh or you can set them to associate with cells in excel.
I did not know that, but I have only used SQL in native SQL or Access. I have never used it with Excel.
I learned something new today!:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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