Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


help writing SUBSTRING() expression please


help writing SUBSTRING() expression please

Author
Message
sumadevu
sumadevu
SSC Veteran
SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)

Group: General Forum Members
Points: 269 Visits: 67
Hi,
For getting the substring except MFM from the SQL Server DB itself,
With MySampleData([Business Unit])
AS
(
SELECT 'MFMGOOGLE' UNION ALL
SELECT 'MFMArnoldDeCaprio' UNION ALL
SELECT 'MFMBruceSchwarzenegger' UNION ALL
SELECT 'MFMArnoldDamon' UNION ALL
SELECT 'MFMLeonardoPitt' UNION ALL
SELECT 'MFMBruceWahlberg'
)
SELECT REPLACE([Business Unit], 'MFM','') FROM MySampleData
sumadevu
sumadevu
SSC Veteran
SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)SSC Veteran (269 reputation)

Group: General Forum Members
Points: 269 Visits: 67
With MySampleData([Business Unit],[Description 01])
AS
(
SELECT 'MFMGOOGLE','ertCOST POOLert' UNION ALL
SELECT 'MFMArnoldDeCaprio','COST ert' UNION ALL
SELECT 'MFMBruceSchwarzenegger','ewtrCOSTwerwer POOL' UNION ALL
SELECT 'MFMArnoldDamon','COSTerwer ' UNION ALL
SELECT 'MFMLeonardoPitt','sdfsf' UNION ALL
SELECT 'MFMBruceWahlberg','fffffCOST_POOL'
)
SELECT
CASE WHEN [Description 01]like '%COST POOL%' AND [Business Unit] like 'MFM%' THEN REPLACE([Business Unit], 'MFM','') END
FROM MySampleData where CASE WHEN [Description 01]like '%COST POOL%' AND [Business Unit] like 'MFM%' THEN REPLACE([Business Unit], 'MFM','') END
is not null
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8407 Visits: 19510
KoldCoffee (6/2/2013)
so this is working


To be sure, you could try something like:
SUBSTRING(TRIM([Business Unit]), 1, 3) == "MFM" ? SUBSTRING(TRIM([Business Unit]), 4, 50): [Business Unit]



--snip

I've tried this but it doesn't parse:

FINDSTRING([Description 01], "COST POOL", 1))==1?SadSUBSTRING(TRIM([Business Unit]), 1, 3) == "MFM" ? SUBSTRING(TRIM([Business Unit]), 4, 50): [Business Unit])


I plan to put it into the Conditional Split transformation. Can you help me with the Expression?


Check this link for examples of the syntax for nested conditional expressions in SSIS. Your syntax is not complete.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
KoldCoffee
KoldCoffee
SSC Eights!
SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)

Group: General Forum Members
Points: 839 Visits: 1905
According to that site this should work (proper operands and use of parentheses):

FINDSTRING(TRIM([Description 01]), "COST POOL", 1))==1?(SUBSTRING(TRIM([Business Unit]), 1, 3) == "MFM" )?(SUBSTRING(TRIM([Business Unit]), 4, 50):[Business Unit])))

SSIS rejects. Can you see the trouble?
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8407 Visits: 19510
Well, I counted only one colon (Smile even though you have two conditions. Everything needs to balance.

No nesting:

expression1?true1:false1

Insert one level of nesting:

expression1?(expression2?true2:false2):false1


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
KoldCoffee
KoldCoffee
SSC Eights!
SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)

Group: General Forum Members
Points: 839 Visits: 1905
let me step back to one expression and go from there.


FINDSTRING([Description 01],"COST POOL", 1)==1? "Yes": "No"

This is the equivalent of
expression1?(expression2?true2:false2):false1

what is wrong with that????
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8407 Visits: 19510
What do you mean by 'wrong'? Looks OK to me. Does it not parse?


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
KoldCoffee
KoldCoffee
SSC Eights!
SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)

Group: General Forum Members
Points: 839 Visits: 1905
it does not parse.:-P
Phil Parkin
Phil Parkin
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8407 Visits: 19510
KoldCoffee (6/3/2013)
it does not parse.:-P


I just created a text file to check this. It parses for me.

--Edit: added screen shot


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
Attachments
Screen shot.jpg (5 views, 13.00 KB)
KoldCoffee
KoldCoffee
SSC Eights!
SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)SSC Eights! (839 reputation)

Group: General Forum Members
Points: 839 Visits: 1905
This morning FINDSTRING([Description 01],"COST POOL", 1)==1? "Yes": "No" parsed. So back to the original problem.

I need one level of nesting to handle second condition. Following SQLChik's tutorial...
Field == "TrueCondition1" ? “True” : ( Field == "TrueCondition2" ? “True” : ( Field == "TrueCondition3 " ? “True” : ( Field == "TrueCondition4" ? “True” : “False" ) ) )


I note there are many TRUEs and one FALSE if all hopes are dashed, so I do this:


FINDSTRING([Description 01],"COST POOL", 1)==1? SUBSTRING(TRIM([Business Unit]), 1,3)=="MFM"?SadSUBSTRING(TRIM([Business Unit]), 4,50)): NULL


Translated: see if the string "Cost Pool" exists in [Description 01] column, if it does, see if first 3 letters of [Business Unit] are "MFM", if yes, retain the letters after MFM. But, if "Cost Pool" doesn't exist, put NULL in column.

This expression doesn't parse. Is it because I am missing parentheses?
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