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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:52:40+00:00 2026-06-17T18:52:40+00:00

I am observing a strange behaviour. The following code that is related to conversion

  • 0

I am observing a strange behaviour. The following code that is related to conversion of a substring of nvarchar to tinyint works fine:

DECLARE @s nvarchar(50) = N'Line 1'
DECLARE @n tinyint = SUBSTRING(@s, 6, 10)

SELECT
        N'Line 1' AS explicit_nvarchar,
        @s AS nvarchar_variable,
        SUBSTRING(@s, 6, 10) AS nvarchar_substring
        , @n AS tinyint_var_converted_earlier
        , CAST(SUBSTRING(@s, 6, 10) AS tinyint) AS cast_sub_var
        , CAST(SUBSTRING(N'Line 1', 6, 10) AS tinyint) AS cast_nvarchar_substr

I can observe the following output in the Microsoft SQL Server Management Studio:

enter image description here.

However, the code that tries to do with the SELECT from the tables fails if the commented line is uncommented:

Select 
    [order].[identifier] As [order_identifier],
    [plan_data].[starts_on] As [from],
    [plan_data].[ends_on] As [to],
    [workplace].[identifier] AS line_identifier,
    SUBSTRING([workplace].[identifier], 6, 10) AS line_no_str
    --, CAST(SUBSTRING([workplace].[identifier], 6, 10) AS int) AS line_no
From 
    ...

With commented line…
enter image description here

but with uncommented line (both for conversion to tinyint or int)…

enter image description here

Update: Strange. I have added the last line to the WHERE to check whether all lines
contain the 'Line...

Where
    [plan].[identifier] = @lPlanIdentifier And
    (
        [plan_data].[starts_on] Between @fromUTC And @toUTC Or
        [plan_data].[ends_on] Between @fromUTC And @toUTC)
    AND LEFT([workplace].[identifier], 4) = N'Line'

… and all of a sudden it works also with the uncommented line. How can I discover what causes the problem?

Update2: I should have followed the Hamlet Hakobyan’s answer exactly as it was published. When looking inside the table, I can see:

enter image description here

  • 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-17T18:52:41+00:00Added an answer on June 17, 2026 at 6:52 pm

    You have value in identifier column for which SUBSTRING([workplace].[identifier], 6, 10) returns ined.

    Try this query:

    SELECT * FROM [workplace]
    WHERE SUBSTRING([identifier], 6, 10) = N'ined'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started dealing with NSOperations and (as usual with concurrency) I'm observing strange behaviour.
I'm observing some strange behavior when using the F# interactive interpreter. Running the following
Observing a strange behavior of this piece of code,because resultset is not giving the
I'm observing a strange behavior scheduling a job in Quartz using a CronTrigger that
I am observing a strange bug in some of my code which I suspect
A behaviour i'm observing w.r.t passing serializable data as intent extra is quite strange,
I was observing today that by writing the below line in a simple java
I'm observing some strange behavior in my code and I'm trying to track down
I'm observing a very strange behaviour with an entity class and loading an object
I am observing strange behaviour of std::map::clear(). This method is supposed to call element's

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.