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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:22:27+00:00 2026-05-27T22:22:27+00:00

I am puzzled by the output of the following query: select ‘Eq Type’ =

  • 0

I am puzzled by the output of the following query:

select 
  'Eq Type' =
  case
    when 
      substring([Eq Type], 1, charindex('-', [Eq Type]) - 1) = 
      substring([Eq Type], charindex('-', [Eq Type]) + 1, len([Eq Type])) 
    then
      substring([Eq Type], 1, charindex('-', [Eq Type]) - 1)
    when
      substring([Eq Type], 1, charindex('-', [Eq Type]) - 1) <> 
      substring([Eq Type], charindex('-', [Eq Type]) + 1, len([Eq Type]))
    then
      replace([Eq Type], '-', '')
    else
      null
  end,
  'Failure_Class' =
  case
    when charindex('-', [Eq Type]) <> 0 and
      (substring([Eq Type], 1, charindex('-', [Eq Type]) - 1) = 
      substring([Eq Type], charindex('-', [Eq Type]) + 1, len([Eq Type])))
    then
      substring([Eq Type], 1, charindex('-', [Eq Type]) - 1)
    when charindex('-', [Eq Type]) <> 0 and
      (substring([Eq Type], 1, charindex('-', [Eq Type]) - 1) <>
      substring([Eq Type], charindex('-', [Eq Type]) + 1, len([Eq Type])))
    then
      substring([Eq Type], 1, charindex('-', [Eq Type]) - 1) +
      '\' +
      replace([Eq Type], '-', '')
    when CHARINDEX('-', [Eq Type]) = 0
    then 
      Failure_Class
    else
      null
  end
from dbo.Location
  1. The Location table contains 25385 records but only 8157 records are returned. Why are records filtered out?

  2. When I try to add into dbo.ModifiedLocation to the above query, it fails with the following error: “Invalid length parameter passed to the LEFT or SUBSTRING function”. The message is pretty descriptive but why this error is raised when I add the into clause? Why is the query executed normally without the into clause?

Edit
I would like to explain what I am trying to achieve. The original dataset has two columns I am interested in, Eq Type and Failure_Class. The data looks as follows:

Eq Type, Failure_Class
ACCU-ACCU, ACCU
AUX-AUX, AUX
VA-BA, VA
VA-CH, VA
IP-LS, IP
null, null
VE, VE
JB, JB
VA, null

Because the data is maintained by hand, it’s inconsistent. I need the data in the following format, in order to be able to import it into their asset management system.

Eq Type, Failure_Class
ACCU, ACCU
AUX, AUX
VABA, VA\VABA
VACH, VA\VACH
IPLS, IP\IPLS
null, null
VE, VE
JB, JB
VA, VA

Edit 2
It seems that I have found the problem. I was running this query in the freeware version of Toad 5.6 for SQL Server. When I have switched to SSMS and removed the “into dbo.ModifiedLocation” the query raised the familiar “Invalid length parameter passed to the LEFT or SUBSTRING function” error. This answers my second question. I am guessing that if I resolve this error, I’ll get the desired output. Thank you for your help.

  • 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-27T22:22:27+00:00Added an answer on May 27, 2026 at 10:22 pm

    To insert into an existing table, you need INSERT INTO dbo.ModifiedLocation SELECT ...

    The SELECT ... INTO dbo.ModifiedLocation FROM ... syntax is for creating the table as well as inserting into it.

    As for the number of records returned. Unless you have a JOIN, or a WHERE clause, or a GROUP BY, or a DISTINCT, this should return exactly the same number of records as exists in the source table.

    Is this exactly the query you are running?

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

Sidebar

Related Questions

Why the following two code samples produce different output? Case 1 enum EnumType {
I'm puzzled about the execution order of the following: $('#home').live('pageinit',function(){ $('#test').hide(); $(function() { alert('test1');
I'm a bit puzzled about the conditional operator. Consider the following two lines: Float
In the following code, why does 2 give output but not 3? The removechars
Consider the following situation: I want to replace links in a string, specifically I
I was following The Joy of Clojure and I am puzzled with these 2
I am puzzled by the following behavior of Function : In[1]:= InlineCellInMessage=Function[expr,DisplayForm[Cell[BoxData[MakeBoxes[expr,StandardForm]],Input]],{HoldAllComplete}] Out[1]= Function[expr,MakeBoxes[expr,StandardForm]]
I think it is MergeSort, which is O(n log n). However, the following output
I am puzzled by why the output is not what I expect it to
I am puzzled why this return false doesn't cancel the post-back. function validate() {

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.