473,395 Members | 1,484 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with MID() function

27
I'm trying to split a text field ex: (10.00" od x 7.50" id) into 2 fields putting everything before the "x" into one column and everything after into another. I was able to achieve that using the Left() and Mid() functions. But I've run into a problem not all of the fields have an "x" some just have one dimension ex: (3.50" od) and the Mid() function returns that into the 2nd column, I need that 2nd column to be Null if there is no "x". This is what i have so far

ID SIZE: Mid([Bar Stock Inventory].[DESCRIPTION],IIf(InStr([Bar Stock Inventory].[DESCRIPTION],"x")>0,0,0)+1,+10)

I'm pretty sure I have the right formula but I don't know what to put instead of >0,0,0

HELP
Aug 18 '09 #1
6 4731
Delerna
1,134 Expert 1GB
Check for the existence of x and if it exists then return the function result otherwise return null

PS. That dosn't look like TSQL syntax.
Aug 18 '09 #2
kini113
27
Sorry had it under the wrong topic heading it's not TSQL it's MS SQL
Aug 19 '09 #3
ck9663
2,878 Expert 2GB
Post what you have so far.

--- CK
Aug 20 '09 #4
kini113
27
For the OD size this is what i have and it's working great.

OD SIZE: Left([Purchase Info Bar Inventory]!DESCRIPTION,InStr([Purchase Info Bar Inventory]!DESCRIPTION,"od")+1)

For the ID Size this is working somewhat it gives me the ID size when there is an ID size seperated by an "x" but if there is no ID size and no "x" it repeats the OD size instead of giving me a Null value ( this is my problem i need the Null value)

ID SIZE: Mid([Purchase Info Bar Inventory]!DESCRIPTION,InStr([Purchase Info Bar Inventory]!DESCRIPTION,"x")+1,+10)

All of the this is in SQL format to be used in a query

I tried using both the Right() and Len() function but since my data is inconsistant I opted for the Mid() and "x" is unique to the field it is only used between the OD and ID size that is why I picked it for equation
This is a sample of the data which is imported from other softeware and there is no set format for entry into that program.

10.00" od x 7.50" id
10.00" od (solid bar of metal)
10.000" od x 7.500" id
10" od x 7.5" id
10.00" od x 7.50" id rough turned

Thanks for any help you can give

Cindy
Aug 20 '09 #5
Delerna
1,134 Expert 1GB
That looks like MS ACCESS syntax

in which case something like the following pseudo code
Expand|Select|Wrap|Line Numbers
  1. [ID Size]:
  2. iif(FormulaToCheckIfXExistInDescription
  3. ,FormulaToRetrieveTheIDSize
  4. ,"")
  5.  
I think your Instr formula will return 0 if x dosn't exist and its position within Description if it does.

Or is it -1 if it does not exist. I can't remember offhand.
Create a new field temporarily with the instr function alone and you will soon see what value to test for
Aug 20 '09 #6
ck9663
2,878 Expert 2GB
Use PATINDEX() to get the position of the "X", then substring up to that value-1 for the first field and get substring from that value+1 to the end of string to get the second.

Good luck!!

-- CK
Aug 22 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Horhayson | last post by:
Trying to fix a web site I inherited. Problem is with the *help* page. User fills out form and hits send. The browser comes back with Error Number 424, Error Description Object Required, Key Name...
10
by: Ken VdB | last post by:
Hi everyone, Is there a reason why the Mid() function only works in one direction in VBScript? This code works in VB6 but not in VBScript? Is there a way around it? I am trying to create an...
6
by: Nawab | last post by:
Hey can anyone explain to me the difference between Mid and Mid$ ....i notice sometimes when i a running the update query with Mid$ it tells me that for example 3 records will be updated ( which in...
1
by: Wayne Aprato | last post by:
The following code which automatically reconnects a database backend by Peter Vukovic works well except for one minor glitch. On the first opening of the frontend, a message box appears saying that...
4
by: Mel | last post by:
Hi, When you use a RichText box (I'm using Microsoft Control VB 6.0, OLE Class: RichtextCtrl) It is possible to store only the text in the table instead of the rft format? The problem is when...
3
by: martlaco1 | last post by:
Trying to fix a query that (I thought) had worked once upon a time, and I keep getting a Data Type Mismatch error whenever I enter any criteria for an expression using a Mid function. Without the...
4
by: Andy_Khosravi | last post by:
Hello, I'm having a problem with the MID function within Access 97. I have been trying to build a function to check to make sure that a field on a form does not have any spaces or dashes. This...
50
by: sabarish | last post by:
Hi to all. find out the biggest among two numbers without using any conditional statements and any relational operators.
1
by: hardik | last post by:
can anyone tell me how i can change the filename which is going to uploaded here is a code for uploading a file <!-- #include file="clsUpload.asp" --> Set objUpload = New clsUpload If...
1
by: karen987 | last post by:
I have an ASP news page to which you can add comments. The comments open up in a new window, and users can click reply to reply to them after which they are taken to the parent page which has a...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...

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.