I am in the processing of preparing for migration to a new database system for a stock based retail store. In the current database products which have been deactivated have a leading * added to the record.
The owners do not want to bring deactivated products into the new system so this leading * is my only reference point to work from.
I need to create a SELECT query that will exclude products that have a leading * but so for to no avail.
I have tried the below
SELECT prdcod
FROM prdtbl
WHERE prodcod<>'*%';
The first 10 results returned are:
I suspect I may not be able to use the * as an excluding factor
Any thoughts would be appreceated
try this
SELECT prdcod
FROM prdtbl
WHERE prodcod not like '*%';
This can be done in so many ways..
Using NOT LIKE
SELECT prdcod
FROM prdtbl
WHERE prodcod NOT LIKE '*%'
Using LEFT/SUBSTRING
SELECT prdcod
FROM prdtbl
WHERE LEFT(prodcod,1) <> '*' -- SUBSTRING(prodcod from 1 for 1) <> '*'
Note : Not Like
is preferred approach if you have a Index
on prodcod
column
SELECT prdcod
FROM prdtbl
WHERE prodcod NOT LIKE '*%';
instead of using "<>" operator, use "not like":
Select prdcod
From prdtbl
Where prodcod not like '*%';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.