473,947 Members | 26,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PROBLEM using CharIndex(), IF, OR etc- PLEASE HELP

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).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 2 _
& ",charindex('GO V',[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ") AS Drivergrp2 " _
& "FROM mars.dbo.mroInv entoryProductGr eeks_Latest
" _
& "Where producttype = 'creditdefaults wap' " _
& "AND exposureName like '" &
Worksheets(4).R ange("j5") & "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0) & "%' "
_

Much appreciation if you can help

May 10 '07 #1
2 3013
SB
On May 11, 5:09 am, matthewwha...@g mail.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).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 2 _
& ",charindex('GO V',[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ") AS Drivergrp2 " _
& "FROM mars.dbo.mroInv entoryProductGr eeks_Latest
" _
& "Where producttype = 'creditdefaults wap' " _
& "AND exposureName like '" &
Worksheets(4).R ange("j5") & "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("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).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 2 _
& ",
isnull(nullif(i snull(nullif(ch arindex('GOV',[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ",0), charindex('FWD' ,[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& "),0), charindex('LIB' ,[exposurename])-"
&
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ")
) AS Drivergrp2 " _
& "FROM mars.dbo.mroInv entoryProductGr eeks_Latest
" _
& "Where producttype = 'creditdefaults wap' " _
& "AND exposureName like '" &
Worksheets(4).R ange("j5") & "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0) & "%' "

May 11 '07 #2
SB
On May 11, 11:02 am, SB <othell...@yaho o.comwrote:
On May 11, 5:09 am, matthewwha...@g mail.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).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 2 _
& ",charindex('GO V',[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ") AS Drivergrp2 " _
& "FROM mars.dbo.mroInv entoryProductGr eeks_Latest
" _
& "Where producttype = 'creditdefaults wap' " _
& "AND exposureName like '" &
Worksheets(4).R ange("j5") & "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("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).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 2 _
& ",
isnull(nullif(i snull(nullif(ch arindex('GOV',[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ",0), charindex('FWD' ,[exposurename])-" &
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& "),0), charindex('LIB' ,[exposurename])-"
&
Len(Worksheets( 4).Range("j5") _
& "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0)) + 3 _
& ")
) AS Drivergrp2 " _
& "FROM mars.dbo.mroInv entoryProductGr eeks_Latest
" _
& "Where producttype = 'creditdefaults wap' " _
& "AND exposureName like '" &
Worksheets(4).R ange("j5") & "_VAR_" &
Worksheets(4).R ange("C4").Offs et(Worksheets(4 ).Range("c3"), 0) & "%' "- Hide quoted text -

- Show quoted text -
There is an elegant way to do this. However your excel ranges are too
big to accommodate that solution. Basically, you switch your string
positions in charindex function. Therefore, instead of looking for GOV
in target string, you take the whole target string and match with GOV.
It is something like:
Strip out gov etc: Substring(targe t_string,...)
Then you do: charindex('stri pped string', 'GOV,FWD,LIB')
And if your target string is small (in your case probably it isn't)
then you can directly use it in charindex as: charindex('sour ce
string', 'GOV,FWD,LIB')
Maybe in your excel you can create an extra column where you store the
stripped column then you can just match it with 'GOV,FWD,LIB'.
HTH.

May 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1865
by: Robin Tucker | last post by:
My code prints out 0 for the value of charindex ( 'Hello.', '.' ). Did I miss something? I think it should print out 6!
5
41585
by: M Wells | last post by:
Hi All, Just wondering if it's any more efficient to use the following SQL statement to return a partial match from a column as opposed to the second statement. SELECT * FROM Table1 WHERE CHARINDEX('value', mycol) > 0 Versus:
14
16259
by: sdowney717 | last post by:
Using the the NumId from TitleData, I would like to delete the corresponding row in Bookdata using pure SQL. I want it to delete all rows in bookdata where the Titledata.NumID is a match to bookdata.id The two tables are linked in that the NumId of table Titledata is identical to the Id of table bookdata. I can, using ADO, loop thru deleting one by one but I would like to do this in a pure SQL statement. Is this possible? Any help is...
5
42051
by: Willem | last post by:
Hello I am quite hopeless and of course a newbe. The situation: Sql2k / query I would like it ot break down the following string: 2004 Inventory:Ex.Plant Farm1:1st Cut:Premium:0094
3
6016
by: csomberg | last post by:
SQL Server 2000 Ya know, it is always the simplest stuff that gets ya !! I am having the hardest time getting a simple piece of code working. Must be brain dead today. Goal: Get the users full name from a string Here is sample data:
3
3113
by: chudson007 | last post by:
With the syntax below, why is field1a not "A" if field1 does not contain "_" SELECT Field1a = CASE WHEN (field1 LIKE '%_%') THEN (charindex('_', field1)) ELSE 'A' END, field1 FROM
11
3179
by: youngster94 | last post by:
Hey all, I've written a VB.Net app that creates picture badges complete with barcodes. The problem is that the barcode quality is not good enough to be read by scanners. I'm using the DRAWSTRING function to place the barcode on the image, but no matter what graphics settings (.InterpolationMode/.CompositingQuality etc.) I manipulate, the barcode image remains poor quality. For exaple I'm using a solidbrush that is black, but some of...
1
2416
by: chudson007 | last post by:
I have a field containing a string with '/' in it multiple times. How can I return the charindex of the last occurance of '/' in the string? Regards, Ciarán
1
3704
by: db55 | last post by:
This script doesn't work. Why? UPDATE SET = LTRIM(SUBSTRING(, 1, convert(bigint, CHARINDEX(',', Comments)-1))) WHERE NOT( IS NULL) AND LEN() > 8 Basically, I'm trying to move everything before a comma into and everything after the comma into . The comments 2 script works. See below.
0
3405
by: anonieko | last post by:
This approach I found very efficient and FAST when compared to the rowcount, or Subquery Approaches. This is before the advent of a ranking function from DB such as ROW_NUMBER() in SQL Server 2005 and the likes of it. So This one works with SQL2000 What do you think?
0
10164
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10694
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6118
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4948
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4540
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3544
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.