473,383 Members | 1,748 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,383 software developers and data experts.

Deciphering INSTR Code

Hello;

A friend gave me this syntax and they are unavailable at the moment and I need this asap. I am trying to figure out how SQL figures this out. Below the syntax takes a field in a file and breaks apart the pieces of the key for other uses. The field looks like this 1234567*AWD*07FA (or 1234567*FPER*07FA). I just need to understand how the numbers behind the TA_2007_ID field work to break apart they key?? The first one is easy.. it just gets the first 7 numbers. The first part is the only one where it is consistantly 7 numbers.. the others vary depending on the award.

Thanks in advance...

SELECT a.* ,substr(a.TA_2007_ID, 1,7) as student_id

,substr(a.TA_2007_ID,INSTR(a.TA_2007_ID,'*', 1, 1)+1,INSTR(a.TA_2007_ID,'*',1,2)-INSTR(a.TA_2007_ID,'*', 1, 1)-1) as award_only

,substr(a.TA_2007_ID,INSTR(a.TA_2007_ID,'*', 1, 2)+1,INSTR(a.TA_2007_ID,'*',1,2)-INSTR(a.TA_2007_ID,'*', 1, 1)+4) as term_only

FROM COLL_PRODUCTION.TA_2007 A
Jun 6 '07 #1
3 2601
Motoma
3,237 Expert 2GB
I think this link should be able to explain everything that is going on in that query.

Come back if you need more help.
Jun 7 '07 #2
Thanks... I was able to get a better understanding of the INSTR command through all your help.. I also gathered...

As you probably know, INSTR finds the starting position of a string within another string. The parameters are INSTR(char1, char2, x, y)
char1 is the string to search
char2 is the string to look for
x is position in char1 to begin the search (so your code is starting at the beginning)
y is the occurrence of char2 to find (so your code will find the first occurrence)

SUBSTR takes the string, the starting position, and the # of characters to cut out.
The first INSTR finds the position of the first *, and adds 1 to move past the * and get the first real character.
To calculate how many characters to return, find the position of the SECOND * and subtract the position of the FIRST *. That gives you the length of the middle string.
Jun 7 '07 #3
Motoma
3,237 Expert 2GB
I am glad you were able to find your solution, and it made me quite happy to see what you learned articulated so eloquently. Thank you for posting a response that others may learn from.

Hope to see more from you here at The Scripts.
Jun 7 '07 #4

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

Similar topics

5
by: DTB | last post by:
I am trying to convert a complex function from Oracle to SQL Server and have come across Oracle's Instr() function. I see SQL Server has CHARINDEX() which is similar, however it does not provide...
5
by: drdeadpan | last post by:
I asked the DBA to start the Server with options -T1204 and -T3605 and here's what I get. I need help deciphering this. This happens when we have 5 usrs performing concurrent actions and for the...
4
by: cloudx | last post by:
hi there, how do I translate the following vb code to C#? I know to use Indexof, but what would be for """"? Thanks! InStr(1, sDocName, """")
5
by: PJSimon | last post by:
Let's say I want to find the occurance of SearchString in MyString, but I want to search without regard to case ... Which is better and why in VB.Net? Index = Instr(MyString, SearchString) - 1...
2
by: brad | last post by:
Hello all, I'm new to javascript--not too new to a few other programming languages--and I need your help deciphering the Regexp in the following string. Regular expresions are hard enough in...
4
by: fischerspooner | last post by:
Hi, I'm banging my head against the desk because I can't find a solution for the following simple problem. Case: There is a column in a table that has FamilyName and FirstName(s) in one field....
12
by: rodchar | last post by:
hey all, i'm getting a result that i don't understand i have a string "test1, test2" If InStr("test1") and InStr("test2") Then 'Inside EndIf The inside is not running for some reason. Any...
3
by: Alex Pavluck | last post by:
I have a date stored like this '2004 - 2006' and I use this code to get startyear and stopyear StartYear: Trim(Left(,InStr(,"-")-1)) StopYear: Trim(Right(,InStr(,"-")-1)) Is there a way to...
13
colinod
by: colinod | last post by:
I have a page that uses a session variable that stores items like a shopping cart, all this works fine but i am trying to code a button that removes an item, i have a page that i have set up for the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.