wasabi3689
asked on
network path query
I need to construct a query to display a folder name only from the network path table, ie the table name is "networkpath"
I have a network path field with the data like below
\\testsql3\document\ICS\20 18\2018345 67\abc.doc
\\testsql3\document\ICS\20 0834567\ab c.doc
\\testsql3\document\ICS\20 07\2018345 67\abc.doc
....etc
What I want from the output
1. only the folder names right after ICS
2. If the folder names right after ICS is more than 4 digit like 2018, 2017...etc skip entire row selection, I only want the folder name more than 4 digit like 201834567
In above example
The result is only 200834567 shown
I have a network path field with the data like below
\\testsql3\document\ICS\20
\\testsql3\document\ICS\20
\\testsql3\document\ICS\20
....etc
What I want from the output
1. only the folder names right after ICS
2. If the folder names right after ICS is more than 4 digit like 2018, 2017...etc skip entire row selection, I only want the folder name more than 4 digit like 201834567
In above example
The result is only 200834567 shown
ASKER
from should be a table
select ...
from table name
where..
why you put the sample values in from???
select ...
from table name
where..
why you put the sample values in from???
ASKER
can this work?
SELECT SUBSTRING(networkstring, CHARINDEX('ICS\', networkstring) + 4,
PATINDEX('%[^0-9]%', SUBSTRING(networkstring+'\ ', CHARINDEX('ICS\', networkstring) + 4, 100)) - 1)
FROM networkpath
WHERE SUBSTRING(networkstring, charindex('ICS\', networkstring) + 8, 1) LIKE '[0-9]'
SELECT SUBSTRING(networkstring, CHARINDEX('ICS\', networkstring) + 4,
PATINDEX('%[^0-9]%', SUBSTRING(networkstring+'\
FROM networkpath
WHERE SUBSTRING(networkstring, charindex('ICS\', networkstring) + 8, 1) LIKE '[0-9]'
Yes. I just used that as sample data so I could actually run the code.
You can definitely replace the "(VALUES(...) networkpath(...)" part with your own table name, as you've shown.
You can definitely replace the "(VALUES(...) networkpath(...)" part with your own table name, as you've shown.
ASKER
Here is my query, but no record returned
SELECT SUBSTRING(sourceDocPath, CHARINDEX('ICSStorage\', sourceDocPath) + 4,
PATINDEX('%[^0-9]%', SUBSTRING(sourceDocPath+'\ ', CHARINDEX('ICSStorage\', sourceDocPath) + 4, 100)) - 1)
FROM HPMG_full_ScanDocExtract_I nc36
WHERE SUBSTRING(sourceDocPath, charindex('ICSStorage\', sourceDocPath) + 8, 1) LIKE '[0-9]'
This is sample data
\\testsql3\NGProductionDoc s\NGSource Docs\ICSSt orage\2008 0208\20F27 A07-C484-4 495-B8CB-E 8C2BDCB973 C.tif
\\testsql3\NGProductionDoc s\NGSource Docs\ICSSt orage\2018 \20181108\ A9C5CB9C-2 D0F-4547-A 947-47DCA4 626913.tif
SELECT SUBSTRING(sourceDocPath, CHARINDEX('ICSStorage\', sourceDocPath) + 4,
PATINDEX('%[^0-9]%', SUBSTRING(sourceDocPath+'\
FROM HPMG_full_ScanDocExtract_I
WHERE SUBSTRING(sourceDocPath, charindex('ICSStorage\', sourceDocPath) + 8, 1) LIKE '[0-9]'
This is sample data
\\testsql3\NGProductionDoc
\\testsql3\NGProductionDoc
So it's not necessarily 'ICS\' but could be 'ICSanything\'?
SELECT networkstring, SUBSTRING(networkstring, ICS_Start, PATINDEX('%[^0-9]%',
SUBSTRING(networkstring+'\ ', ICS_Start, 100)) - 1)
FROM (VALUES
('\\testsql3\NGProductionD ocs\NGSour ceDocs\ICS Storage\20 080208\20F 27A07-C484 -4495-B8CB -E8C2BDCB9 73C.tif'),
('\\testsql3\NGProductionD ocs\NGSour ceDocs\ICS Storage\20 18\2018110 8\A9C5CB9C -2D0F-4547 -A947-47DC A4626913.t if')
)as networkpath(networkstring)
CROSS APPLY (
SELECT CHARINDEX('\', networkstring, CHARINDEX('ICS', networkstring)) + 1 AS ICS_start
) AS alias1
WHERE SUBSTRING(networkstring, ICS_start + 4, 1) LIKE '[0-9]'
SELECT networkstring, SUBSTRING(networkstring, ICS_Start, PATINDEX('%[^0-9]%',
SUBSTRING(networkstring+'\
FROM (VALUES
('\\testsql3\NGProductionD
('\\testsql3\NGProductionD
)as networkpath(networkstring)
CROSS APPLY (
SELECT CHARINDEX('\', networkstring, CHARINDEX('ICS', networkstring)) + 1 AS ICS_start
) AS alias1
WHERE SUBSTRING(networkstring, ICS_start + 4, 1) LIKE '[0-9]'
ASKER
here is the query I run
SELECT sourceDocPath, SUBSTRING(sourceDocPath, ICS_Start, PATINDEX('%[^0-9]%',
SUBSTRING(sourceDocPath+'\ ', ICS_Start, 100)) - 1)
FROM HPMG_full_ScanDocExtract_I nc36
CROSS APPLY (
SELECT CHARINDEX('\', sourceDocPath, CHARINDEX('ICS', sourceDocPath)) + 1 AS ICS_start
) AS alias1
WHERE SUBSTRING(sourceDocPath, ICS_start + 4, 1) LIKE '[0-9]'
I got the full path returned
\\testsql3\NGProductionDoc s\NGSource Docs\ICSSt orage\2011 0618\B25CA 97E-C0A5-4 D79-B990-C DD88B53778 9.pdf
\\testsql3\NGProductionDoc s\NGSource Docs\ICSSt orage\2011 0618\A0AC9 F2B-29A7-4 002-883C-2 3B234DDBEF C.pdf
\\testsql3\NGProductionDoc s\NGSource Docs\ICSSt orage\2011 0618\C11CD 6B4-7FF2-4 065-8924-0 B29051FF56 C.pdf
SELECT sourceDocPath, SUBSTRING(sourceDocPath, ICS_Start, PATINDEX('%[^0-9]%',
SUBSTRING(sourceDocPath+'\
FROM HPMG_full_ScanDocExtract_I
CROSS APPLY (
SELECT CHARINDEX('\', sourceDocPath, CHARINDEX('ICS', sourceDocPath)) + 1 AS ICS_start
) AS alias1
WHERE SUBSTRING(sourceDocPath, ICS_start + 4, 1) LIKE '[0-9]'
I got the full path returned
\\testsql3\NGProductionDoc
\\testsql3\NGProductionDoc
\\testsql3\NGProductionDoc
here is the query I run
SELECT sourceDocPath, SUBSTRING(sourceDocPath, ICS_Start, PATINDEX('%[^0-9]%',
SUBSTRING(sourceDocPath+'\', ICS_Start, 100)) - 1)
FROM HPMG_full_ScanDocExtract_Inc36
CROSS APPLY (
SELECT CHARINDEX('\', sourceDocPath, CHARINDEX('ICS', sourceDocPath)) + 1 AS ICS_start
) AS alias1
WHERE SUBSTRING(sourceDocPath, ICS_start + 4, 1) LIKE '[0-9]'
I got the full path returned
The first column in the SELECT is the full path, so, yes, the full path will be returned, since you requested it.
What value is in the second column returned from the SELECT?
ASKER
What I want from the output
1. only the folder names right after \ICSStorage\
2. If the folder names right after \ICSStorage\ is 4 digit like 2018, 2017...etc skip entire row selection, I only want the folder name more than 4 digit like 201834567
1. only the folder names right after \ICSStorage\
2. If the folder names right after \ICSStorage\ is 4 digit like 2018, 2017...etc skip entire row selection, I only want the folder name more than 4 digit like 201834567
I'll let someone else come in then, or you can delete the q and restart.
Good luck.
Good luck.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
PATINDEX('%[^0-9]%', SUBSTRING(networkstring+'\
FROM (VALUES
('\\testsql3\document\ICS\
('\\testsql3\document\ICS\
('\\testsql3\document\ICS\
WHERE SUBSTRING(networkstring, charindex('ICS\', networkstring) + 8, 1) LIKE '[0-9]'