Reputation: 31
I'm starting to learn SQL. Im using SQL Server Management Studio to write my queries in. I unserstand that I can filter a field contaning a given value (for example : product A, product A (cost), product B, product B (cost)) so in this instance I can filter out values containing "(cost)". I've arrived at the following query but its failing. Can you tell me why.
SELECT billing_code, billing_code_desc
FROM dbo.jm_billing_code
WHERE (NOT (billing_code_desc = N'CONTAIN [(cost)]'))
ORDER BY billing_code
Upvotes: 3
Views: 13713
Reputation: 63
Try:
SELECT billing_code, billing_code_desc FROM dbo.jm_billing_Code
WHERE billing_code_desc NOT LIKE '%(Cost)%'
ORDER BY billing_code
Upvotes: 1
Reputation: 18364
If you are trying to filter for rows that have (cost)
in billing_code_desc
then you should do
AND CONTAINS(billing_code_desc, '(cost)')
See contains
Upvotes: 1
Reputation: 10325
WHERE NOT(CONTAINS(billing_code_desc, N'cost'))
Should fix your problem.
Upvotes: 1
Reputation: 238296
N'CONTAIN [(cost)]'
is a string literal, you can't place functions like contain
in there.
Try this instead:
where billing_code_desc not like '%(cost)%'
Upvotes: 4
Reputation: 31630
To exclude results that have cost:
SELECT billing_code, billing_code_desc
FROM dbo.jm_billing_code
WHERE billing_code_desc NOT LIKE '%(cost)%'
ORDER BY billing_code
Upvotes: 3