vdr1620
asked on
Convert Excel function to SQL
Need help converting this Excel nested If function to SQL script
=RIGHT(B1,LEN(B1)-IF(OR(MI D(B1,1,1)= "0",MID(B1 ,1,1)="9") ,
IF(OR(MID(B1,2,1)="0",MID( B1,2,1)="1 "),
IF(OR(MID(B1,3,1)="0",AND( MID(B1,3,1 )="1",MID( B1,1,3)<>" 001"),MID( B1,1,3)="9 00"),
IF(OR(MID(B1,4,1)="0",MID( B1,1,4)="9 011",AND(M ID(B1,1,5) ="00021",L EFT(R95,2) ="BR")),
IF(OR(MID(B1,5,1)="0",AND( MID(B1,1,5 )="00021", LEFT(R95,2 )="BR")),
IF(MID(B1,6,1)="0",6,5),4) ,3),2),1), 0))
Ex: 00039019746598 should result in 39019746598
Appreciate your Help!!!!!!!
=RIGHT(B1,LEN(B1)-IF(OR(MI
IF(OR(MID(B1,2,1)="0",MID(
IF(OR(MID(B1,3,1)="0",AND(
IF(OR(MID(B1,4,1)="0",MID(
IF(OR(MID(B1,5,1)="0",AND(
IF(MID(B1,6,1)="0",6,5),4)
Ex: 00039019746598 should result in 39019746598
Appreciate your Help!!!!!!!
Please state your requirements in a few sentences :)
vdr - your basic structure will be as follows. From your previous question, I think you have a sense of how to write the SQL, you just needed the structure. Your Excel expression has 6 conditions to test and that's reflected in the structure below. Have a look and let me know us know if you need more detailed assistance.
IF ( Boolean_expression1 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression2 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression3 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression4 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression5 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression6 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
Sql Statement Block
END
END
END
END
END
END
IF ( Boolean_expression1 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression2 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression3 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression4 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression5 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
IF ( Boolean_expression6 )
BEGIN
Sql Statement Block
END
ELSE
BEGIN
Sql Statement Block
END
END
END
END
END
END
Previous Question: If Expression in Excel
To put this into context of your previous question:
Boolean Expression1 (BE1) is the equivalent of A: in the decision tree
Boolean Expression2 (BE2) = B:
BE3 = C:
BE4 = D:
BE5 = E:
BE6 = F:
Also, you'll need to use SUBSTRING() instead of MID(): MSDN SUBSTRING()
Boolean Expression1 (BE1) is the equivalent of A: in the decision tree
Boolean Expression2 (BE2) = B:
BE3 = C:
BE4 = D:
BE5 = E:
BE6 = F:
Also, you'll need to use SUBSTRING() instead of MID(): MSDN SUBSTRING()
Rather than sifting through a bunch of excel functions, can you just state the criteria in English?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again Mark for trying to put this together.. but i wanted to do this using CASE rather than IF as you will not be able to implement IF in an Inline statement
Thanks acperkins... this is exactly what i was looking for.. I will test it and let you know
Thanks acperkins... this is exactly what i was looking for.. I will test it and let you know
No worries, vdr. Hope ac's solution works for you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
aikimark, I did try negating the conditions but ran into a snag and thought it would not work.. but you proved me wrong... Thanks
ASKER
Thank you guys..