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 9244835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:07:46+00:00 2026-06-18T09:07:46+00:00

I have a table that stores data about a large number of files, such

  • 0

I have a table that stores data about a large number of files, such as their language, unique ID, file path etc. I want to be able to get the sub-string from the unique ID which gives me the asset type, this is always the first 2 letters of the ID. I then want to group these asset types by language and have a count for how many of each type every language has. So at the end I would ideally like a table that has a language column and then a column for each substring (asset type).

I have tried to create a large switch statement but this isn’t very reliable and I was told maybe linq would be better. I don’t have much experience with linq or sql and I have a couple of sql queries I’ve tried that gets me one part of the desired results, but I was hoping maybe someone who has more experience might know how to group these functions into one statement.

SELECT 
  LCID,
  SUBSTRING(AssetID,1,2)  
FROM [table]

this gets me the correct substrings, but I have multiple rows for each language. Is there any way to group the same languages into one column and then count how many of each type there are? Thanks

sample data from current query
desired results

  • 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-18T09:07:47+00:00Added an answer on June 18, 2026 at 9:07 am

    Sounds like you want a COUNT and a GROUP BY:

    SELECT 
      SUBSTRING(AssetID,1,2), 
      COUNT(*) Total
    FROM [table]
    GROUP BY SUBSTRING(AssetID,1,2)
    

    You did not specify what database but, if you are using SQL Server and LCID is in your SELECT statement, then you will need to include it in your GROUP BY clause.

    If the LCID value is unique for each row then you will get multiple records for each AssetID because it will try to group the unique values together. As a result, I removed the LCID.

    If it is not unique, then you can use:

    SELECT LCID, 
      SUBSTRING(AssetID,1,2), 
      COUNT(*) Total
    FROM [table]
    GROUP BY LCID, SUBSTRING(AssetID,1,2)
    

    Based on the edits that you made, you want a PIVOT which transforms the data from rows into columns. For a PIVOT you will use:

    select LCID, HA, HT, HP, FH, FX
    from
    (
      SELECT LCID, 
        SUBSTRING(AssetID,1,2) AssetID
      FROM [table]
    ) src
    pivot
    (
      count(AssetID)
      for AssetID in (HA, HT, HP, FH, FX) -- place more values here
    ) piv
    

    If the values are unknown that you want to transform into columns, then you will need to use dynamic SQL similar to this:

    DECLARE @cols AS NVARCHAR(MAX),
        @query  AS NVARCHAR(MAX)
    
    select @cols = STUFF((SELECT distinct ',' + QUOTENAME(SUBSTRING(AssetID,1,2)) 
                        from [table]
                FOR XML PATH(''), TYPE
                ).value('.', 'NVARCHAR(MAX)') 
            ,1,1,'')
    
    set @query = 'SELECT LCID, ' + @cols + ' from 
                 (
                    SELECT LCID, 
                      SUBSTRING(AssetID,1,2) AssetID
                    FROM [table]
                ) x
                pivot 
                (
                    count(AssetID)
                    for AssetID in (' + @cols + ')
                ) p '
    
    execute(@query)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores data that has been entered regarding the amount
I have a table from a vendor application that stores some xml data into
I have an application that stores approximately 24 fields of data about a machine.
I have a stored proc that processes a large amount of data (about 5m
I have a table that stores email in 3 diffrent columns name host and
I have a table that stores user information. The table has a userid (identity)
I have a table that stores various clients I have done work for, separated
I have a table that stores employee names and years they worked. The columns
I have mysql table that has a column that stores xml as a string.
I have a Pages table that stores all my view urls and this 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.