May 16, 2003 at 12:24 pm
Hello all. Is there a way to search for a string that contains a specific number of characters?
I have a project that will be inserting barcode values into the db. One requirement is the ability to query the barcode db for barcode entries that are a specific length, 14 characters.
Any ideas?
Thank you.
ks
Kevin S.
May 16, 2003 at 12:28 pm
You can execute:
SELECT * FROM TableName
WHERE LEN(BarCode) = 14
May 16, 2003 at 12:30 pm
quote:
You can execute:SELECT * FROM TableName
WHERE LEN(BarCode) = 14
Thank you so much my friend!
ks
Kevin S.
May 16, 2003 at 1:36 pm
If the table is very large, and speed becomes a problem, you might want to add a BARCODE_LEN field to the table, and index that field. You could keep the field up to date with insert and update triggers
RD Francis
R David Francis
May 16, 2003 at 1:40 pm
quote:
If the table is very large, and speed becomes a problem, you might want to add a BARCODE_LEN field to the table, and index that field. You could keep the field up to date with insert and update triggersRD Francis
Oh! Excellent. I am fairly new to T-SQL (2 years of mild use) and I appreciate all of your inputs.
Thank you.
ks
Kevin S.
May 16, 2003 at 1:41 pm
quote:
If the table is very large, and speed becomes a problem, you might want to add a BARCODE_LEN field to the table, and index that field...
I hate to be a nay-sayer, but this strategy probably won't help much. The selectivity of the data in the BARCODE_LEN field would be so minimal (maybe a variation of 5 or 6 data values?) that an index probably wouldn't help much. Having the data field there as a calculated field will only eliminate the calculation of the LEN function on the BarCode field, which is probably not an extensive use of resources. As a side bar, it might be an interesting test to populate a table with millions of rows and see at what point a calculated field of datalength would significantly improve a query's performance. rdfozz, feel up to it?
May 17, 2003 at 11:01 pm
Is the requirement of n characters the only requirement?
How about a view and two tables, one for n character length barcodes and the other for the none n length barcodes.
Insert on view with an instead trigger.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply