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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:04:05+00:00 2026-05-16T21:04:05+00:00

— Given a CSV string like this: declare @roles varchar(800) select @roles = ‘Pub,RegUser,ServiceAdmin’

  • 0
-- Given a CSV string like this:

declare @roles varchar(800)
select  @roles = 'Pub,RegUser,ServiceAdmin'

-- Question: How to get roles into a table view like this:

select  'Pub'
union
select  'RegUser'
union
select  'ServiceAdmin'

After posting this, I started playing with some dynamic SQL. This seems to work, but seems like there might be some security risks by using dynamic SQL – thoughts on this?

declare @rolesSql varchar(800)
select  @rolesSql = 'select ''' + replace(@roles, ',', ''' union select ''') + ''''
exec(@rolesSql)
  • 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-16T21:04:05+00:00Added an answer on May 16, 2026 at 9:04 pm

    See my answer from here

    But basically you would:

    Create this function in your DB:

    CREATE FUNCTION dbo.Split(@origString varchar(max), @Delimiter char(1))     
    returns @temptable TABLE (items varchar(max))     
    as     
    begin     
        declare @idx int     
        declare @split varchar(max)     
    
        select @idx = 1     
            if len(@origString )<1 or @origString is null  return     
    
        while @idx!= 0     
        begin     
            set @idx = charindex(@Delimiter,@origString)     
            if @idx!=0     
                set @split= left(@origString,@idx - 1)     
            else     
                set @split= @origString
    
            if(len(@split)>0)
                insert into @temptable(Items) values(@split)     
    
            set @origString= right(@origString,len(@origString) - @idx)     
            if len(@origString) = 0 break     
        end 
    return     
    end
    

    and then call the function and pass in the string you want to split.

    Select * From dbo.Split(@roles, ',')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I'm doing: public static String htmlToText(String inString) { String noentity=StringEscapeUtils.unescapeHtml(inString); return
I'm including a local class that requests a file from a remote server. This
By fixed vector I mean a static list of values, like 1 through 24.
My app uses a WebRequest at certain points to get pages from itself. This
This is a follow-up to the question: Should the folders in a solution match
&mdash; or &#8212; Is there a difference between these? Is one better-supported than the
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I recently ran against a very interesting site that expresses a very interesting idea
I basically have the classic many to many model. A user, an award, and
I'm using some of Firefox's specially-defined values for cursor, in particular -moz-zoom-in -moz-zoom-out -moz-grab

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.