Solved

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

Posted on 2004-09-20
3
475 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
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

770 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