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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:00:24+00:00 2026-06-02T22:00:24+00:00

I’ve got a table that has a column where the codes are a string

  • 0

I’ve got a table that has a column where the codes are a string that starts with from 2 to 4 characters then may or may not have a space then it has a number. For example: KR123 or KS 23 or K23456. The following SQL Code on SQL Server 2008 will return just the number:

Select CONVERT(int, Reverse(LEFT(REVERSE(codefield),PATINDEX('%[a-z]%', REVERSE(codefield)) - 1)))
From Table1

This works great in SQL, but one of the programmers I work with wants to use LINQ to Entites to do the same thing. I tried this code in VB.Net just to see if I could get the index value of the reversed field from the first row:

Dim theResult = theContext.Table1.select(function(y) 
              System.Data.Objects.SQLClient.SQLFunctions.PatIndex("%[a-z]%", y.codefield.Reverse)
                        ).FirstOrDefault

It compiles fine, but this gives me the error when it runs: LINQ to Entities does not recognize the method ‘System.Collections.Generic.IEnumerable1[System.Char] Reverse[Char](System.Collections.Generic.IEnumerable1[System.Char])’ method, and this method cannot be translated into a store expression.

If I remove the .Reverse, it works, but I need to be able to reverse the column data for the code to correctly work.

Can anyone figure out how to do the original select using LINQ to Entities?

Thanks,
NCGrimbo

  • 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-02T22:00:32+00:00Added an answer on June 2, 2026 at 10:00 pm

    If you need numbers why don’t you just match on the number instead of text – something like this:

    SELECT SUBSTRING(Name, PATINDEX('%[0-9]%', Name), 200)
    FROM Entities
    

    (The 200 (or whatever number suites you – I wish there was Int.Max in T-SQL) is arbitrary just to not deal with calculating the length of the string – if the length is bigger than the string the whole substring starting at start position will be returned)

    Now the query in Linq to Entities is pretty simple (sorry for using C#):

    var q = ctx.Table1.Select( y => 
                y.codefield.Substring(
                   (int)SqlFunctions.PatIndex("%[0-9]%", y.codefield) - 1));
    

    Note that Entity Framework will come up with the code calculating the string length. You can avoid it again by using the trick with the arbitrary big number like this:

    var q = ctx.Table1.Select( y => 
                y.codefield.Substring(
                  (int)SqlFunctions.PatIndex("%[0-9]%", y.codefield) - 1, 
                  Int.Max));
    

    Back to the original question – you can use Reverse but in a bit different way:

    var q = ctx.Table1.
                Select(y => 
                   SqlFunctions.PatIndex("%[a-z]%", EntityFunctions.Reverse(y.codefield)));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
i got an object with contents of html markup in it, for example: string
Does anyone know how can I replace this 2 symbol below from the string

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.