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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:48:12+00:00 2026-05-23T13:48:12+00:00

I have a function Split which I am calling in a stored proc with

  • 0

I have a function “Split” which I am calling in a stored proc with cursor.

My a_upload table structure is: (int, varchar(100))

upload_id   allowed_file_extensions
---------------------------------------------------------------------
1           .xls, .doc, .pdf, .docx, .xlsx, .pptx, .txt
2           .xls, .doc, .pdf, .jpeg, .jpg, .docx, .xlsx, .pptx, .txt

table c_file_extensions is: (int, varchar(100), bit)

id  description  is_enabled
---------------------------
1   .xls         1
2   .doc         1
3   .pdf         0
4   .rtf         1

Stored proc:

DECLARE @is_enabled Varchar(10), @allowed_file_extensions Varchar(100)

   SET @is_enabled = 'True';

DECLARE cur CURSOR FORWARD_ONLY FOR 
  SELECT items 
    FROM split((SELECT allowed_file_extensions 
                  FROM a_upload 
                 WHERE upload_id = 1), ',') 

OPEN cur
FETCH NEXT FROM cur INTO @allowed_file_extensions
WHILE @@fetch_status=0
BEGIN

    IF EXISTS(SELECT * 
                FROM c_file_extensions 
               WHERE description = @allowed_file_extensions 
                 AND is_enabled = 0)
      SET @is_enabled = 'False';

FETCH NEXT FROM cur INTO @allowed_file_extensions
END
CLOSE cur
DEALLOCATE cur

SELECT @is_enabled AS Output

function split:

CREATE FUNCTION dbo.Split(@String varchar(8000), @Delimiter char(1))       
  RETURNS @temptable TABLE (items varchar(8000)) AS

BEGIN
    DECLARE @idx int       
    DECLARE @slice varchar(8000)       

    SELECT @idx = 1    

    IF LEN(@String) < 1 OR @String IS NULL RETURN

    WHILE @idx!= 0       
    BEGIN       
        SET @idx = CHARINDEX(@Delimiter,@String)       
        IF @idx != 0       
          SET @slice = LEFT(@String,@idx - 1)       
        ELSE       
          SET @slice = @String       

          IF(LEN(@slice)>0)  
            INSERT INTO @temptable
             (Items) 
            VALUES
             (@slice)       

          SET @String = RIGHT(@String, LEN(@String) - @idx)       
          IF LEN(@String) = 0 BREAK
    END  
RETURN      
END  

For upload_id = 1, I am expecting the output to be ‘False‘, but I always get ‘True‘. I tried to debug, and found that the “if exists (select * from c_file_extensions where description = @allowed_file_extensions and is_enabled = 0)” is not working properly.

  • 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-23T13:48:13+00:00Added an answer on May 23, 2026 at 1:48 pm

    This is happening because you’re comparing against items with leading spaces.

    Try this:

      select items from split((select ext from a_upload where id = 1), ',') 
    

    This results in:

    .xls
     .doc
     .pdf
     .docx
     .xlsx
     .pptx
     .txt
    

    To solve this, you could:

    • modify your cursor definition:
    select  LTRIM(items) from split((select ext from a_upload where id = 1), ',') 
    
    • modify your dbo.split() to remove leading spaces on Line 29:
    set @String = LTRIM(right(@String,len(@String) - @idx))  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: SQL Server 2005 I have a stored proc which receives comma separated value
Hi I have the following code in which I am calling a function named
I have used split function to split the string in javascript. which is as,
I have a Stored Proc query below which involves returning partial delimited search string.
I currently have this function which appends an input to the #cursor-start div: var
I have custom function which return a table it accepts two varchars, it splits
Currently i have this: $(.splitCol).click(function () { $.cookie('whichColumn', 'split'); $(.threeCol .active).removeClass(active); $(.leftCol .active).removeClass(active); $(.splitCol
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function: char *zap(char *ar) { char pie[100] = INSERT INTO test (nazwa,
If I have function names stored as strings in a Hashtable. Is there 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.