Search code examples
sqlsql-serverssis-2012

Remove the ending parentheses in SQL SSIS variable using expression builder?


Passing variable in the SSIS, it used to fetch/pass the query.Issue is incoming query contains ";" parenthesis in the end like this ));

This is causing issue how to remove the parenthesis using expression building in SSIS

"SELECT DISTINCT 
col1,
col2,
FROM(
"+
@[User::Query]+")Das"

Here is my attempt:

   "SELECT DISTINCT 
    col1,
    col2,
    FROM(DT_WSTR)REPLACE("+
@[User::Query]+",";",""))Das"

Second one

"SELECT 
Col1,Col2,
FROM(
"+
(DT_WSTR, "20")FINDSTRING( ( @[User::Query]), ";",1 )  == "1" ? RTRIM( @[User::Query]): ( @[User::Query])+")DM"

This is able to remove the ';' but it remove the character before the ';' also (SELECT Col1,Col2,FROM)

How to remove the )); automatically using expression builder?


Solution

  • Here is the answer

    (DT_WSTR, "20")FINDSTRING( REVERSE( @[User::Query]), ";",1 )  == "1" ?
    "SELECT DISTINCT CHANNEL, TRACK, MODULE, FEATURE FROM("+ SUBSTRING( @[User::Query] , 1,  LEN(@[User::Query])-1) +")DM"
    :
    "SELECT DISTINCT CHANNEL, TRACK, MODULE, FEATURE FROM("+@[User::Query]+")DM"
    

    Kindly post you options