Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8208421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:21:42+00:00 2026-06-07T09:21:42+00:00

I have a table with a column called ExcelLinks that contain records like this:

  • 0

I have a table with a column called ExcelLinks that contain records like this:

=INDEX(‘\\san1\engData[BT_500.0_Structural_Position.xls]Concrete’!$B$4:$IK$83,MATCH($K$9,’\\san1\engData[BT_500.0_Structural_Position.xls]Concrete’!$A$4:$A$83,0),MATCH(C212,’\\san1\engData[BT_500.0_Structural_Position.xls]Concrete’!$B$3:$IK$3,0))/1000000

=INDEX(‘\\san1\engData[GK_600.0_Pumps.xls]Pumps’!$B$4:$BD$39,MATCH($K$9,’\\san1\engData[TT_640.0_Generator.xls]Generator’!$A$4:$A$39,0),MATCH(C214,’\\san1\engData[GK_600.0_Pumps.xls]Pumps’!$B$3:$BD$3,0))/1000000

=INDEX(‘\\san1\engData[TT_640.0_Generator.xls]Generator’!$B$4:$HU$83,MATCH($K$9,’\\san1\engData[GK_600.0_Pumps.xls]Pumps’!$A$4:$A$83,0),MATCH(C218,’\\san1\engData[TT_640.0_Generator.xls]Generator’!$B$3:$HU$3,0))/1000000

The ideal output would be:

_______________________________________
| Row  |  LinkCount |  UniqueLinkCount |
| 1    |     3      |        1         |
| 2    |     3      |        2         |
| 3    |     3      |        2         |

I want to query this data and see the number of files and unique files used per record.

I did a search online and couldn’t find anything that does this.

I’m thinking I’ll make a cursor and for each record I’ll detect chars starting with \\ and ending with '!$ and count the number of files.

The hard bit is the ExcelLinks with the =INDEX and MATCH functions that use multiple interlinks (that could be different files).

There’s over 12 million records in this table so I am concerned about the performance using a cursor.

There are some better ways to do this with Oracle using RegEx’s. I know that SQL Server doesn’t have RegEx and am willing to write/use a CLR stored proc if that’s the easiest option.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:21:45+00:00Added an answer on June 7, 2026 at 9:21 am

    First, grab this string splitting CLR function from Adam Machanic. Compile the code into a DLL (using csc if you don’t have Visual Studio), copy the DLL to your server, and then register the DLL as follows (you’ll have to replace some variable parts here, such as the file path, what you want to call the assembly, etc.):

    CREATE ASSEMBLY CLRStuff 
      FROM 'C:\DLLs\CLRStuff.dll'  
      WITH PERMISSION_SET = SAFE;
    GO
    
    CREATE FUNCTION dbo.SplitStrings
    (
       @List      NVARCHAR(MAX),
       @Delimiter NVARCHAR(255)
    )
    RETURNS TABLE ( Item NVARCHAR(4000) )
      EXTERNAL NAME CLRStuff.UserDefinedFunctions.SplitString_Multi;
    GO
    

    With that in place, the query itself is quite easy. Let’s create a simple table variable holding a few rows (I shortened the paths for brevity):

    DECLARE @x TABLE(i INT, ExcelLink VARCHAR(MAX));
    
    INSERT @x
    
        -- 3 files, 1 unique: 
        SELECT 1,'=INDEX(''\\san1\a.xls''!$B$4:$IK$83,MATCH($K$9,''\\san1\a.xls'
        + '''!$A$4:$A$83,0),MATCH(C212,''\\san1\a.xls''!$B$3:$IK$3,0))/1000000'
    
    UNION ALL 
    
        -- 3 files, 3 unique:
        SELECT 2,'=INDEX(''\\san1\a.xls''!$B$4:$BD$39,MATCH($K$9,''\\san1\b.xls'
        + '''!$A$4:$A$39,0),MATCH(C214,''\\san1\c.xls''!$B$3:$BD$3,0))/1000000'
    
    UNION ALL 
    
        -- 3 files, 2 unique:
        SELECT 3,'=INDEX(''\\san1\b.xls''!$B$4:$HU$83,MATCH($K$9,''\\san1\c.xls'
        + '''!$A$4:$A$83,0),MATCH(C218,''\\san1\c.xls''!$B$3:$HU$3,0))/1000000'
    
    UNION ALL 
    
        -- 1 file, 1 unique:
        SELECT 4,'=INDEX(''\\san1\foo.xls''!$B$4:$HU$83,0)';
    
    -- the above was just inserts; the remainder is all of the query:
    
    ;WITH x(i,part) AS 
    (
      SELECT x.i, SUBSTRING(t.Item, CHARINDEX('''\\', t.Item), 2048) 
        FROM @x AS x CROSS APPLY dbo.SplitStrings(x.ExcelLink, '!$') AS t
    )
    SELECT i, [file_count] = COUNT(part), [unique_files] = COUNT(DISTINCT part)
      FROM x WHERE part LIKE '''\\%'
      GROUP BY i ORDER BY i;
    

    Results:

    i   file_count  unique_files
    --  ----------  ------------
    1   3           1
    2   3           3
    3   3           2
    4   1           1
    

    This relies on \\ not appearing naturally in the data other than as the beginning of a file path, and that all file paths reside on a network share.

    This is probably not the most efficient you can get – I’m sure some RegEx wizard can improve this using that approach instead of splitting (here is a good article to get you started), but that’s not my forte. A large portion of the cost is going to be the I/O required to scan the entire table, rather than the counting or the replacing.

    If you can’t use CLR, you can substitute that function for any number of non-CLR versions (here is an example that would be a functionally suitable replacement), but keep in mind other approaches will likely suffer from less optimal performance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a value in my MS SQL table column called XDATA like this:
If I have table with a Date column called myDate , with values like
I have a table that has a certain numeric column called Score . I
I have a database table with a column called 'symbol', that is unique via
I have timestamps in a table column called last_seen like so: 2012-01-25 18:46:42 2012-01-23
I have a table called Users that has a column called deleted, a boolean
I have a table (lets say it has one column called 'colLanguage') that contains
I have a table (MySQL) that has a column called binID. The values in
I have a table X that has column called version that has 4-5 values
I have a table that I added a column called phone - the table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.