I've always enjoyed SQL but this one has go me thinking.
It's SharePoint related, in that, I'm querying a SharePoint database directly from SQL management studio.
The query is based around the document naming convention within the organisation.
It must be:
YYYYMMDD_name.doc (etc)
Example:
20100913-Eat A Sandwich.doc
Only the following characters are allowed:
A-Z, a-z, 0-9, hyphen, round brackets, space, underscore.
So, I'm trying to right a query that will find any documents that don't conform to the naming convention AND that contain illegal characters:
Example:
20100913-Eat A Sandwich$$.doc (although in the right format, contains illegal charaters)
Eat A Sandwich_20100913-.doc (not in the right format)
Here's what I have so far:
(BTW, for those not familiar with SharePoint tables, LeafName is the field that contains the document name)
As it stands, that query returns the docs with illegal characters just fine, but not those with the correct naming format that might contain illegal characters.
It's SharePoint related, in that, I'm querying a SharePoint database directly from SQL management studio.
The query is based around the document naming convention within the organisation.
It must be:
YYYYMMDD_name.doc (etc)
Example:
20100913-Eat A Sandwich.doc
Only the following characters are allowed:
A-Z, a-z, 0-9, hyphen, round brackets, space, underscore.
So, I'm trying to right a query that will find any documents that don't conform to the naming convention AND that contain illegal characters:
Example:
20100913-Eat A Sandwich$$.doc (although in the right format, contains illegal charaters)
Eat A Sandwich_20100913-.doc (not in the right format)
Here's what I have so far:
(BTW, for those not familiar with SharePoint tables, LeafName is the field that contains the document name)
Code:
- Illegal characters
SELECT *
FROM Docs
WHERE LeafName LIKE '%[^-a-zA-Z0-9()_ ]%.[a-zA-Z0-9][a-zA-Z0-9][a-zA-Z0-9]%'
AND LeafName != ''
-- Start
AND LeafName NOT LIKE '[0-2][019][0-9][0-9]%'
As it stands, that query returns the docs with illegal characters just fine, but not those with the correct naming format that might contain illegal characters.
Last edited: