Columns That Contain a Value
This applies to cases where your T-SQL query might include a clause like this:
col LIKE '%value%'The SSIS expression equivalent involves the function FINDSTRING. FINDSTRING looks in any string expression (including a column) for an occurrence of a particular substring, and which occurrence to look for.
The equivalent expression in SSIS to the example above is:
FINDSTRING(col, "value", 1) > 0Columns That Start With a Value
This applies to cases where your T-SQL query might include a clause like this (where X is a number):
col LIKE 'value%'
or
LEFT(col, X) = 'value'This is a fairly rudimentary case - and there are multiple methods for developing an equivalent SSIS expression with FINDSTRING, or LEFT, such as:
FINDSTRING(col, "value", 1) == 1or
LEFT(col, X) == "value"Columns That End With a Value
This one's a little trickier (in SSIS2008R2 and below), and has prompted a few questions on the MSDN SSIS forums. The T-SQL case would look something like:
RIGHT(col, X) = 'value'There's a LEFT in SSIS' expression language... but no RIGHT prior to SSIS 2012, so what can you do? How about using REVERSE and LEFT, like this:
REVERSE(LEFT(REVERSE(col), X)) == "value"More Complicated Demands?
T-SQL's LIKE can service more complicated pattern searching - look for future posts where I'll try to investigate some. If you have any particular requests, post a comment...
Hi Todd,
ReplyDeleteWouldn't the last example be:
REVERSE(LEFT(REVERSE(col), X)) == "value"
Instead of:
LEFT(REVERSE(col), X) == "value"
In other words, shouldn't we reverse back before matching?
hi todd,
ReplyDeletefindstring() function looks similar to charindex() function of t-sql, and even maybe patindex() function of t-sql as well.
thank you very much,
tonci korsano
Absolutely, Boyan! Thanks for catching that - I'll fix it up.
ReplyDeleteIt should also be noted that FINDSTRING() is a case sensitive comparison between the col and value. Wrapping your col or values in LOWER() or UPPER() will resolve issues with casing in your comparison.
ReplyDeleteI realize this original post is a few years old, but I came across it today looking up the functionality you posted for an SSIS project. Thank you for the information!
Todd, NEw to SSIS but I am desperately trying to find a SSIS equivalent way to do a SQL "IN" expression in a where clause. As in, I have a table with a list of values AA,AB and I want to populate a variable with the list and have used in a where expression, as in where gblt IN (AA,AB,AC). The variable populates correctly but for the life of me I can't get it to do what I want - but seems so elementary. Is there no simple way to filter data via an IN statement in SSIS?
ReplyDelete