?
Solved

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

Posted on 2004-09-20
3
Medium Priority
?
504 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

801 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