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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:39:49+00:00 2026-05-16T18:39:49+00:00

I have the following UDF. CREATE FUNCTION [dbo].[udf_GenerateVarcharTableFromStringList] (@list varchar(MAX), @delimiter char(1) = N’,’)

  • 0

I have the following UDF.

CREATE FUNCTION [dbo].[udf_GenerateVarcharTableFromStringList]
        (@list      varchar(MAX),
         @delimiter char(1) = N',')
    RETURNS @tbl TABLE ([Value]     varchar(200)) 
    WITH SCHEMABINDING
    AS
    BEGIN
       DECLARE @chrind INT
       DECLARE @Piece nvarchar(4000)

       SELECT @chrind = 1
       WHILE @chrind > 0
          BEGIN
            SELECT @chrind = CHARINDEX(@delimiter,@list)
             IF @chrind > 0
                SELECT @Piece = LEFT(@list,@chrind - 1)
             ELSE
                SELECT @Piece = @list
             INSERT @tbl([Value]) VALUES(@Piece)
             SELECT @list = RIGHT(@list,LEN(@list) - @chrind)
             IF LEN(@list) = 0 BREAK
          END

       RETURN

    END

I call this function with the following code example from a where clause in my sprocs:

WHERE u.[Owner] IN 
 (SELECT [VALUE] 
  FROM dbo.udf_GenerateVarcharTableFromStringList(@Owners, ','))

I use this where statement in sprocs that I use for reporting services multivalue parameters. When a user selects just blank for the value it returns the correct data but if a user selects a blank value and another value that actually has text it does not return the blank value owners anymore, just the owners from the text? Any ideas? I take it something is wrong with the function?

  • 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-16T18:39:50+00:00Added an answer on May 16, 2026 at 6:39 pm

    Well, from what I could gather from your comments it seems that you need a new splitting function. Here’s what I use:

    create FUNCTION [dbo].[fnSplitString] (@s varchar(512),@sep char(1))
    RETURNS table
    AS
    RETURN (
        WITH Pieces(pn, start, stop) AS (
          SELECT 1, 1, CHARINDEX(@sep, @s)
          UNION ALL
          SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
          FROM Pieces
          WHERE stop > 0
        )
        SELECT pn,
          SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
        FROM Pieces
      )
    

    It has a nice enumeration feature to it and it doesn’t eat blanks. 🙂

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

Sidebar

Related Questions

I have an existing view that returns data in the following format based on
I have following 2 tables Channels: Id int PK Title varchar SubChannels: ChannelId int
I have the the following query: SELECT * FROM dbo.tblOrders o WHERE o.OrderId IN
I have following problem: My program should decide at runtime to load an function
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following situation. A main table and many other tables linked together with
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public

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.