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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:34:10+00:00 2026-05-26T19:34:10+00:00

how to pass the concatenation String into SQL SELECT IN () ? DECLARE @NextString

  • 0

how to pass the concatenation String into SQL SELECT IN () ?

DECLARE @NextString NVARCHAR(40)
DECLARE @Pos INT
DECLARE @NextPos INT
DECLARE @String NVARCHAR(40)
DECLARE @Delimiter NVARCHAR(40)

SET @String ='1,2'
SET @Delimiter = ','
SET @String = @String + @Delimiter
SET @Pos = charindex(@Delimiter,@String)

WHILE (@pos <> 0)
BEGIN
SET @NextString = substring(@String,1,@Pos - 1)
SELECT @NextString -- Show Results
SET @String = substring(@String,@pos+1,len(@String))
SET @pos = charindex(@Delimiter,@String)

SELECT ADRESSE, AGENCE, AUTRE_REF, CHAUFFEUR, CODE_CLIENT, CODE_DEST, CODE_MAG, CP, CREE_PAR, DATE_CLOTUR, DATE_CREE, DATE_MODIF, EMAIL, ENLEV_CREMB, ENLEV_DECL, ENLEV_UNITE, FACTURATION, FAX, INSEE, LIVRS_EXPRS, LIVRS_SAMD, LIVRS_SIGN, MODAL_MODE, MODAL_PORT, MODAL_SPEC, MODIF_PAR, NBR_COLIS, NO_ORDRE, OBS, PAYS, POID, POID_COR, REF_EXPED, RS_NOM, SIRET, STATUT_ORDRE, TEL, TRANSPORTEUR, VILLE FROM ORDRE WHERE (STATUT_ORDRE = 2) AND (TRANSPORTEUR IN (@NextString))
END 

i tried with this, but in not work exactly what i expected.

Thanks you in advance,
Stev

  • 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-26T19:34:11+00:00Added an answer on May 26, 2026 at 7:34 pm

    if you know how many parameters in @NextString, you can use
    TRANSPORTEUR IN (@parm1,@parm2,@parm3......)
    OR you need to use the exec to execute the sql
    declare @sql varchar(max)
    set @sql='SELECT ADRESSE, AGENCE, AUTRE_REF,
    CHAUFFEUR, CODE_CLIENT, CODE_DEST,
    CODE_MAG, CP, CREE_PAR, DATE_CLOTUR,
    DATE_CREE, DATE_MODIF, EMAIL,
    ENLEV_CREMB, ENLEV_DECL, ENLEV_UNITE, FACTURATION,
    FAX, INSEE, LIVRS_EXPRS, LIVRS_SAMD, LIVRS_SIGN,
    MODAL_MODE, MODAL_PORT, MODAL_SPEC, MODIF_PAR, NBR_COLIS,
    NO_ORDRE, OBS, PAYS, POID, POID_COR, REF_EXPED, RS_NOM, SIRET, STATUT_ORDRE, TEL, TRANSPORTEUR, VILLE FROM ORDRE WHERE (STATUT_ORDRE = 2) AND (TRANSPORTEUR IN (' + @NextString + '))'

    exec (@sql)
    and you should set the @NextString as '''p1'',''p2'',''p3'''

    ==================================================================================
    update on 11-Jan-2013

    create the spiting function

    CREATE FUNCTION [dbo].[udf_Split]    
    ( @Words nvarchar(MAX)    
    , @splitStr varchar(50)    
    )    
    RETURNS @Result_Table TABLE    
    (    
    [word] nvarchar(max) NULL    
    )    
    BEGIN    
    Declare @TempStr nvarchar(MAX)    
    WHILE (CHARINDEX(@splitStr,@Words)>0)    
    BEGIN    
    Set @TempStr=SUBSTRING(@Words,1,CHARINDEX(@splitStr,@Words)-1)    
    Insert into @Result_Table (word) Values (rtrim(ltrim(@TempStr)))    
    Set @Words = REPLACE(@Words,@TempStr+@splitStr,'')    
    END    
    IF(LEN(RTRIM(LTRIM(@Words)))>0 And CHARINDEX(@splitStr,RTRIM(LTRIM(@Words)))=0)    
    Begin    
    Set @TempStr=@Words    
    Insert into @Result_Table (word) Values (rtrim(ltrim(@TempStr)))    
    End    
    RETURN    
    END 
    

    then using join instead of using in

    SELECT ADRESSE,
    AGENCE,
    AUTRE_REF,
    CHAUFFEUR,
    CODE_CLIENT,
    CODE_DEST,
    CODE_MAG,
    CP,
    CREE_PAR,
    DATE_CLOTUR,
    DATE_CREE,
    DATE_MODIF,
    EMAIL,
    ENLEV_CREMB,
    ENLEV_DECL,
    ENLEV_UNITE,
    FACTURATION,
    FAX,
    INSEE,
    LIVRS_EXPRS,
    LIVRS_SAMD,
    LIVRS_SIGN,
    MODAL_MODE,
    MODAL_PORT,
    MODAL_SPEC,
    MODIF_PAR,
    NBR_COLIS,
    NO_ORDRE,
    OBS,
    PAYS,
    POID,
    POID_COR,
    REF_EXPED,
    RS_NOM,
    SIRET,
    STATUT_ORDRE,
    TEL,
    TRANSPORTEUR,
    VILLE
    FROM ORDRE a
    INNER JOIN udf_split(@NextString, ',') b
    ON b.word = a.TRANSPORTEUR
    WHERE (STATUT_ORDRE = 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table-valued function such as dbo.Split() from T-SQL: Opposite to string concatenation -
I pass text strings from a configuration file into my Flex app, one of
I pass a vb.net query string to a page with, depending on the parameter,
I am trying to do some string concatenation/formatting, but it's putting all the parameters
In JNI when we want to pass a string from C to java we
I pass some data converting it into json & json outputs like; [{msg:1: AVAILABLE:
we often come across a scenario where in we need to pass a String
I pass in the following XML to XMLin : <root foo=bar foo2=bar2> <pizzas> <pizza>Pepperoni</pizza>
Goal Pass images generated by one process efficiently and at very high speed to
How do you pass $_POST values to a page using cURL ?

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.