Solved

SQL server 2000 - Calculated column - how do i return the first word of a field???

Posted on 2004-09-20
3
496 Views
Last Modified: 2008-03-04
Hi I am trying to create a column in a table that always returns the first part of another field. I need to strip a postcode down to the first part ie "L35 6YT" would be "L35" the first part is between 2 and 4 charactors long so I cant use a simple trimming function. I have done it in access using this code

 Left([IntroducerPostcode],InStr([IntroducerPostcode] & " "," ")-1)

but SQL server 2000 doesnt read the commands??

any ideas? Im doing it so I can compare the postcode in a transactions table to the postcode in another table, but the postcodes stored in the other table are only the first part and not the full code that is stored in the transactions table. Im thinking maybe I can set a join up between the two fields in a query once I can get only the first part to return in the tranactions table.

Hope that makes sense! There may be an easier way to do it in which case let me know!

Cheers!
0
Comment
Question by:goldsmithwilliams
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
solution46 earned 125 total points
ID: 12101616
use charindex instead of InStr

From the SQL Server books online...

CHARINDEX ( expression1 , expression2 [ , start_location ] )

Arguments
expression1

Is an expression containing the sequence of characters to be found. expression1 is an expression of the short character data type category.

expression2

Is an expression, usually a column searched for the specified sequence. expression2 is of the character string data type category.

start_location

Is the character position to start searching for expression1 in expression2. If start_location is not given, is a negative number, or is zero, the search starts at the beginning of expression2.
0
 

Author Comment

by:goldsmithwilliams
ID: 12101706
Thanks,

Im new to SQL so am struggling with this, what should I be putting into the formula box by looking at my access code?

Cheers again!
0
 
LVL 9

Expert Comment

by:solution46
ID: 12102288
Er, your best bet is probably to make a view in SQL Server, using the above SQL, and link to that in Access; then use the usual access notation to use your query in your forms.

If you need any more guidance, please give me a few details of your setup and I'll see what I can do.

s46.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question