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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:59:33+00:00 2026-05-30T08:59:33+00:00

[Apologies for the long winded explanation] I have inherited an aold application with a

  • 0

[Apologies for the long winded explanation]

I have inherited an aold application with a SQL database from an (very!) old product and I need to do some reporting against the DB directly. Not entirely sure WHY but this is the structure I have uncovered:

I have a Groups table, and a Reports table.

Groups has a type column, ‘R’ or ‘G’, an integer numElements and an image column called elements

Type ‘R’ means the Group contains Reports, ‘G’ means it contains more Groups.

type = 'G'
elements = 0x2C002600
numelements = 2
result = take chunks of 4 characters, 
         reverse the last and first two character pairs to get 002C and 0026
convert hex to int to get 44 and 38

44 and 38 are two Group ID’s – I can verify this from within the application itself.

The same applies for type ‘R’ where the ID’s resulting are Reports

Is there any way to Map this behaviour in EF4 OR T-SQL so that I can start to do some sensible queries?
e.g.

If type = G and numElements = 3
    split the hex string into 3 chunks of 4 characters, 
    reverse character pairs, 
    convert to int, 
    map to Groups

If type = R and numElements = 11
    split the hex string into 11 chunks of 4 characters, 
    reverse character pairs, 
    convert to int, 
    map to Reports

There are thousands of reports and hundreds of groups, so although within the application I can see the groupings, to map them manually would take forever. There is no tree view, so I have to open a group to see what it contains, then open sub-groups (if present) etc. etc.

I know I can code this manually and go through line-by-line abnd extract, split, reverse, convert…but wondered if there was a way I could get T-SQL or EF to do this for me?


EDIT:

Please note, the numElements is variable, since a Group can contain 1:Many Groups OR 1:Many Reports (but not a mixture of them). Therefore the hex string is always:
“0x” + “4 x numElements” characters long

This means that the “hex to int” function needs to be able to return an array or similar, so that 1 Group can be linked to Many Groups/Reports.

  • 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-05-30T08:59:35+00:00Added an answer on May 30, 2026 at 8:59 am

    The only thing that will help you with both is to create a scalar function which does that split, reverse and convert.

    I would create three functions:

    dbo.fnSplitHex(varchar hex, int chunks)  -- the actual split etc
    
    dbo.fnSplitGHex(varchar hex) return dbo.fnSplitHex(hex, 3) -- pass 3 for chunks
    dbo.fnSplitRHex(varchar hex) return dbo.fnSplitHex(hex, 11) -- pass 11 for chunks
    

    Unfortunately you can’t create a Navigation Property based on this only. However you can create a view:

      select *, dbo.fnSplitHex(..) from table1
    

    With LINQ 2 SQL I can create a Navigation Property between the view and another table, as long as I define a PrimaryKey for the view, in the model. Not sure with EF… EF also

    Response On Question Edit

    Since the convert function depends on numElements, an external input and not like the hex param which is a column in the main table and can be read from there, you have no option in creating a NavigationProperty between the main table and Groups or Reports.

    Unfortunately your problems don’t stop here. This being a table function (returns a table with a single column of type int), EF can’t use it as a “composable” function, like in the following example:

      from c in Groups
      from sg in fnGetIntsFromHex('G', 3, c.hex) into groups from sg in groups.DefaultIfEmpty()
      join g in Groups on sg.GroupId equals g.GroupId
      select g
    

    This would have to generate a SQL statement with a CROSS APPLY operator, but now it can’t do it (EF 2011 June CTE can, but is CTE).

    What is left? I think going back to stored procedure is not such a bad thing. Other options depends on your numElements set. If this set is limited in a reasonable way, you still can create views like:

    create view dbo.vwSubgropus3
    as
    begin
    
    select f.GroupId, f.Value = SubGroupId
    from group g
    where g.Type = 'G'
    cross apply fnGetIntsFromHex(g.Hex, 3) f
    
    
    create view dbo.vwSubgropus11
    as
    begin
    
    select f.GroupId, f.Value as SubGroupId
    from group g
    where g.Type = 'G'
    cross apply fnGetIntsFromHex(g.Hex, 11) f
    
    
    create view dbo.vwReports3
    as
    begin
    
    select f.GroupId, f.Value as ReportId
    from group g
    where g.Type = 'R'
    cross apply fnGetIntsFromHex(g.Hex, 3) f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apologies in advance for the long-winded question. I'm really a database programmer, but have
I have another Javascript regex conundrum... (apologies if this is a bit long-winded -
Apologies in advance if this becomes a very long question... Background Info I have
Apologies for the long winded title but looking for a solution to what might
Apologies for the rather verbose and long-winded post, but this problem's been perplexing me
Apologies for the long post, I have tried to provide you with as much
I'm pretty new to Nhibernate, so apologies for a long - winded description I
Apologies in advance for rather long post and lot of code. My application has
I need to know if in a database in Sql Server 2008 (would also
Let me first tender my apologies for my question might be too long to

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.