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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:04:46+00:00 2026-06-14T16:04:46+00:00

Situation: I often have (no comments on database, it is history :)) columns where

  • 0

Situation:

I often have (no comments on database, it is history :)) columns where values are separated.

So let’s say we have a column params which contains for example 1,2,3,4,5.

If I need the values table based I split them with a dbo.fn_Split() function (several version can be found on the net – but out of scope here). So I get my virtual table.

Today I ran into a situation where I have a column where I have this content 110&mode=tree.

As I needed the ID only I said to myself… like usual, split and get the first value only:

SELECT TOP 1 [value] FROM dbo._fnSplit('110&mode=tree','&')

As I needed the value as int I added a CAST() around it.

CAST((SELECT TOP 1 [value] FROM dbo._fnSplit('110&mode=tree','&')) AS int)

Now after execution I got:

mode=tree cannot be converted to a type int

Huch? I get only the first value which is an Id (I double checked the results) but it still try to convert the 2nd value as well. So it seems that SQL Server handles it differently in execution.

Question:

So is it generally possible to control how the execution plans handle this behaviour?

Sidenote:

I solved it for now doing this:

[...] WHERE id = CAST((CASE WHEN k.param LIKE '%&%' THEN LEFT(k.swindowparam,PATINDEX('%&%',k.param)-1) ELSE k.swindowparam END) AS int))

Check if string contains & and if so so a LEFT with length found out by PATINDEX.

EDIT:

Here is the split function:

CREATE FUNCTION dbo.fn_Split(@text nvarchar(4000), @delimiter char(1) = ',')

RETURNS @Strings TABLE
(
position int IDENTITY PRIMARY KEY,
value nvarchar(4000)
)

AS
BEGIN

DECLARE @index int
SET @index = -1

SET @text = RTRIM(LTRIM(@text))

WHILE (LEN(@text) > 0)
BEGIN
SET @index = CHARINDEX(@delimiter , @text)
IF (@index = 0) AND (LEN(@text) > 0)
BEGIN
INSERT INTO @Strings VALUES (@text)
BREAK
END
IF (@index > 1)
BEGIN
INSERT INTO @Strings VALUES (LEFT(@text, @index - 1))
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
ELSE
SET @text = RIGHT(@text, (LEN(@text) - @index))
END
RETURN
END
  • 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-14T16:04:47+00:00Added an answer on June 14, 2026 at 4:04 pm

    It sounds like your split function is returning the data in an unspecified order. To solve the problem I would change that function so it returns the results in the expect order every time.

    Depending on how the function is implemented you may be able to correct this behavior by adding an ORDER BY statement. SQL Server doesn’t guarantee that a set will be returned in any specific order by default.

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

Sidebar

Related Questions

I often have this kind of situation - there's a simple plain class, say,
I have to use several shaders. In this situation, which way is often prefered?
I have a situation which come in front of me very often but I
I often have a situation in my Java code when I need to set
Situation: I have an index page which loads pages into it with ajax as
Often I have a situation when I meed to show whole picture but clarify
I am often in a situation where I have a method where something can
I often have the situation where I need several constants generated at compile time
I'm often confronted with the following situation: I have some data in a table
This is a situation that comes up often: In the View, you have a

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.