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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:42:18+00:00 2026-05-25T12:42:18+00:00

i have simple data coming in like this: declare @string varchar(500) = val1|val2|val3 how

  • 0

i have simple data coming in like this:

declare @string varchar(500) = "val1|val2|val3"

how could i split this out into a cte or something similar so i could user it in a later query:

select col1 from table where col2 = @valFromCTE
  • 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-25T12:42:18+00:00Added an answer on May 25, 2026 at 12:42 pm

    This is a helpful and simple way to query a delimited string as if it were a table.

    Taken from:
    http://www.mindsdoor.net/SQLTsql/ParseCSVString.html

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[fn_ParseCSVString]') and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[fn_ParseCSVString]
    GO
    
    
    create function fn_ParseCSVString
    (
    @CSVString  varchar(8000) ,
    @Delimiter  varchar(10)
    )
    returns @tbl table (s varchar(1000))
    as
    /*
    select * from dbo.fn_ParseCSVString ('qwe,c,rew,c,wer', ',c,')
    */
    begin
    declare @i int ,
        @j int
        select  @i = 1
        while @i <= len(@CSVString)
        begin
            select  @j = charindex(@Delimiter, @CSVString, @i)
            if @j = 0
            begin
                select  @j = len(@CSVString) + 1
            end
            insert  @tbl select substring(@CSVString, @i, @j - @i)
            select  @i = @j + len(@Delimiter)
        end
        return
    end
    
    
    GO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a simple piece of data to store (an integer or string
I have a simple data model of two tables, email and recipients, email can
I have only simple data types in method signature of service (such as int,
I have a simple WCF Data Services service and I want to expose a
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package where I import data from flat file into SQL
We have a simple project where we read data from a socket and we
I have a simple object that get's geocoding data from the Google Maps API
I have a simple web.py program to load data. In the server I don't
If I have a simple table where the data is such that the rows

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.