![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
What is the best way to essentially use the charindex(find) function if the value is could be more than one variable (A or B or C) I can't seem to get an "or", "if" or "select if" to work Below is the code that works, I need 'GOV' to be either 'GOV' or 'FWD' or 'LIB' sqlstring = "SELECT Distinct substring([exposurename]," _ & Len(Worksheets(4).Range("j5") & "_VAR_" _ & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 2 _ & ",charindex('GOV',[exposurename])-" & Len(Worksheets(4).Range("j5") _ & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 3 _ & ") AS Drivergrp2 " _ & "FROM mars.dbo.mroInventoryProductGreeks_Latest " _ & "Where producttype = 'creditdefaultswap' " _ & "AND exposureName like '" & Worksheets(4).Range("j5") & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0) & "%' " _ Much appreciation if you can help |
#3
| |||
| |||
|
|
On May 11, 5:09 am, matthewwha... (AT) gmail (DOT) com wrote: What is the best way to essentially use the charindex(find) function if the value is could be more than one variable (A or B or C) I can't seem to get an "or", "if" or "select if" to work Below is the code that works, I need 'GOV' to be either 'GOV' or 'FWD' or 'LIB' sqlstring = "SELECT Distinct substring([exposurename]," _ & Len(Worksheets(4).Range("j5") & "_VAR_" _ & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 2 _ & ",charindex('GOV',[exposurename])-" & Len(Worksheets(4).Range("j5") _ & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 3 _ & ") AS Drivergrp2 " _ & "FROM mars.dbo.mroInventoryProductGreeks_Latest " _ & "Where producttype = 'creditdefaultswap' " _ & "AND exposureName like '" & Worksheets(4).Range("j5") & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0) & "%' " _ Much appreciation if you can help Hi, See if this works. You may have to play with double quotes to get it working since I do not know VB or excel programming. sqlstring = "SELECT Distinct substring([exposurename]," _ & Len(Worksheets(4).Range("j5") & "_VAR_" _ & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 2 _ & ", isnull(nullif(isnull(nullif(charindex('GOV',[exposurename])-" & Len(Worksheets(4).Range("j5") _ & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 3 _ & ",0), charindex('FWD',[exposurename])-" & Len(Worksheets(4).Range("j5") _ & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 3 _ & "),0), charindex('LIB',[exposurename])-" & Len(Worksheets(4).Range("j5") _ & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0)) + 3 _ & ") ) AS Drivergrp2 " _ & "FROM mars.dbo.mroInventoryProductGreeks_Latest " _ & "Where producttype = 'creditdefaultswap' " _ & "AND exposureName like '" & Worksheets(4).Range("j5") & "_VAR_" & Worksheets(4).Range("C4").Offset(Worksheets(4).Ran ge("c3"), 0) & "%' "- Hide quoted text - - Show quoted text - |
![]() |
| Thread Tools | |
| Display Modes | |
| |