SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Multiple Mid functions


Multiple Mid functions

Author
Message
mack53nico
mack53nico
SSC-Addicted
SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)

Group: General Forum Members
Points: 423 Visits: 39
Hi,

Apologies is this query is too specific for this forum, please point me in the right direction if that's the case.

Below is an expression I am using to pull out the forename from a user ID i.e."text\[forename] [Surname]", at the moment this expression is suitable if " " is between the forename and surname. However, what i have noticed is that " " can be replaced by "." or "/" or "_" for example.

The trouble I am having is including multiple "Mid" functions to include all these options. I have attempted using "Or", "Switch" and a number of other operators with no effect.

Am I missing something obvious or have i missed the mark completely?

Any help would be greatly aprpreciated.

= "Hi " + Mid(Parameters!User.Value, InStr(Parameters!User.Value,"\")+1, (InStr(Parameters!User.Value, " ") - InStr(Parameters!User.Value, "\") - 1)) + "," &
chr(10) & chr(13) &
chr(10) & chr(13) &
"You have access to the Teams listed below. Only data from these teams will be shown in any analysis. Please click above to continue to the Dashboards"
Thom A
Thom A
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74300 Visits: 19182
Do you have to do this with an expression? I ask, as it may be easier to return the parts in your dataset, rather than splitting them in the report. For example:
WITH Users AS(
SELECT *
FROM (VALUES ('sabdbsdlkfbaskl f\Steve Jobs'),
(
'asdkbgaksdaskbdk\Jane-Smith'),
(
'kasjdgbasdvajklsvd\Craig.Charles'),
(
'sdfgasdjlfgalsdhfsajldf\Jennifer_Lopez'),
(
'sdiafgaskjdkjhobkjah\Bill/Gates')) V (UserID)),
Names AS(
SELECT U.UserID,
RIGHT(U.UserID, CHARINDEX('\',REVERSE(U.UserID))-1) AS FullName
FROM Users U)
SELECT *,
LEFT(FullName, PATINDEX('%[/ \._-]%',FullName)-1) AS FirstName,
RIGHT(FullName, PATINDEX('%[/ \._-]%',REVERSE(FullName))-1) AS Surname
FROM Names N;

You don't need to do with a CTE, but just easier to see what it's doing, IMO.


Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does :-P

Please always remember to encapsulate your code in IFCode Markup. For example [code=sql] [/code].
Click here to read Jeffs Guide on how to post SQL questions, and get swift and helpful answers from the community
mack53nico
mack53nico
SSC-Addicted
SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)SSC-Addicted (423 reputation)

Group: General Forum Members
Points: 423 Visits: 39
Thank you for your reposnse, however my question is parameter based i.e. i don't actually have/need ( i've simply inputted SELECT 'fred' to avoid any errors).

The UserID as a parameter is generated when a user enters the SSRS report and depending on their permissions, they will recieve the message "You have access.....". It's just that the UserID can include a / . _
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search