Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a parameter value 'Europe - DPS Sweden',
i need to get only Sweden to provide input for the dataset in ssrs.
I have tried with some expressions and not able to get the required result.


Any advice on getting this done

What I have tried:

i tried on sql but couldn't able toget in ssrsexpression

LTRIM(REPLACE(SUBSTRING('Europe - DMS Sweden', CHARINDEX('DMS', 'Europe - DMS Sweden'), LEN('Europe - DMS Sweden')), 'DMS', '')) 
Posted
Updated 4-Jan-18 2:55am
Comments
ZurdoDev 4-Jan-18 7:26am    
The only way to do it is to first define the rules in English and then translate them into SQL.

1 solution

Try reversing the string first, then using charindex to look for the first space. You should also cater for scenarios where there is no space.

For example:
SQL
declare @test varchar(255) = 'Europe - DPS Sweden'
SELECT REVERSE(LEFT(REVERSE(@test), iif(charindex(' ', REVERSE(@test)) = 0, LEN(@test), charindex(' ', REVERSE(@test)) - 1)))
Results
Sweden

Note that this also works if there are no spaces
SQL
SET @test = 'nospaces'
SELECT REVERSE(LEFT(REVERSE(@test), iif(charindex(' ', REVERSE(@test)) = 0, LEN(@test), charindex(' ', REVERSE(@test)) - 1)))
Result
nospaces
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900