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

  • Home
  • SEARCH
  • 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 6765513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:43:13+00:00 2026-05-26T14:43:13+00:00

Here’s a table with a computed column in SQL Server 2005: CREATE TABLE footable

  • 0

Here’s a table with a computed column in SQL Server 2005:

CREATE TABLE footable AS
  [identifier] nvarchar(255) NOT NULL,
  [result]     AS CASE 
    WHEN [identifier] like '%\[%]' escape '\'
    THEN LEFT( [identifier], CHARINDEX('[',[identifier]) - 1 )
    END

Here’s what I’m expecting:

identifier      result
======================
foo[bar]        foo
foo             NULL

This worked a few days ago, and has been working for over a year.

Then yesterday, I started getting this error when inserting or updating with identifier values that had no [, when a NULL would be the expected result:

Invalid length parameter passed to the left function.

Now, today, it’s working again.

Why would SQL Server be attempting to solve the LEFT() function when the CASE is not true?

More importantly, why is it working one day and not the next?

I was also creating some indexed views yesterday, though not covering either of these columns. Could one of the SET options required for indexing a view cause the database to start throwing errors for an expression like this?

  • 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-26T14:43:14+00:00Added an answer on May 26, 2026 at 2:43 pm

    I would use

    N'[^[]%\[%]' escape N'\'  
    

    That should handle the possibility that the first character is a [.

    Or, if you want to return a non-null (empty string?) in that case, use a nested CASE to handle the condition of CHARINDEX returning 1.

    By the way, you don’t really need that escape character or escape clause. You can use [[] to match the [ character:

    N'[^[]%[[]%]'
    

    But, that’s a matter of personal taste. I can see how the escaped version is a little clearer

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

Sidebar

Related Questions

Here's what I'm trying do to in a single SQL Server procedure: @ID1 int
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's an interesting problem. On a recently installed Server 2008 64bit I opened IE
Here is a part of my code: <asp:ListBox ID=lbRD runat=server DataSourceID=RDSqlDataSource onchange=JSFillDetail(); DataTextField=Описание DataValueField=ID
Here is a link my example of the misaligned table rows Click preview in
Here is an example table: ID time data type 0 0100 xyz 0 1
Here is my code: echo '<table class=class1><tbody>'; while ($row1=mysql_fetch_array($result1)){ echo '<tr><td>'.$row1['firstname'].'</td><td>'.$row1['lastname'].'</td></tr>'; } echo '</tbody></table>';
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs

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.