SSIS - Extract filename from file path using TOKEN and TOKENCOUNT

TOKEN and TOKENCOUNT are new string functions introduced from SSIS 2012 .


As mentioned in MSDN :

TOKEN - Returns a token (substring) from a string based on the specified delimiters that separate tokens in the string and the number of the token that denotes which token to be returned. 

Syntax : 
TOKEN(character_expression, delimiter_string, occurrence)
 
TOKENCOUNT - Returns the number of tokens in a string that contains tokens 
separated by the specified delimiters. 
 
Syntax : 
TOKENCOUNT(character_expression, delimiter_string)

Example : (To  extract filename from file path using TOKEN and TOKENCOUNT )

Below expression returns 3 , because delimiter_string "\\" splits the character_expression 
"G:\\GAMES\\fifa.exe" into three parts .

TOKENCOUNT("G:\\GAMES\\fifa.exe", "\\")



  
Below expression returns fifa.exe , because  delimiter_string "\\" splits the character_expression "G:\\GAMES\\fifa.exe" into three parts, Occurrence is specified as 3, so the third token in the string is returned.

TOKEN("G:\\GAMES\\fifa.exe", "\\",3)




 To  extract filename from file path using TOKEN and TOKENCOUNT 

TOKEN("G:\\GAMES\\fifa.exe", "\\", TOKENCOUNT("G:\\GAMES\\fifa.exe", "\\"))


 

For more info & examples :

Token - http://technet.microsoft.com/en-us/library/hh213216.aspx 
TokenCount - http://technet.microsoft.com/en-us/library/hh213135.aspx

2 comments:

Ben B said...

good post, just what i needed. thanks :)

Ben B said...

good post, just what i needed - thanks :)