Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Query in Excel Left() 1

Status
Not open for further replies.

mflancour

MIS
Apr 23, 2002
379
US
I'm in excel 2003 querying external data with microsoft query. All I want to do is the following:
Select left(table.field, 2) from table

I can't seem to find any variation of this that works to let me have a column of data that is either left, mid or right characters.
 

Hi,

I don't understand your question. Your query is OK.

Please explain what is happening and what you want.

Skip,

[glasses] [red]Be Advised![/red] For those this winter, caught in Arctic-like calamity, be consoled...
Many are cold, but few are frozen![tongue]
 
The problem is this gives me an error. It's as if microsoft query does not support the Left() function. Is there another function that does this? or is my syntax incorrect?
 


What type of database are you querying?

Skip,

[glasses] [red]Be Advised![/red] For those this winter, caught in Arctic-like calamity, be consoled...
Many are cold, but few are frozen![tongue]
 


For instance, if you are querying Oracle or DB2, then use the Substring function.
Code:
Select Substr(table.field, 1, 2) from table


Skip,

[glasses] [red]Be Advised![/red] For those this winter, caught in Arctic-like calamity, be consoled...
Many are cold, but few are frozen![tongue]
 
I'm not at work now so I can't test this,but it looks like exactly what I needed. thanks.
 
Finally got arround to testing this and it turns out it does not actualy work :( Has anyone used Microsoft query withing excel to get only a portion of a string?
 



Use Left, Mid or Right.

Please post the code you are using within the context of the entire query.

Skip,

[glasses] [red]Be Advised![/red] Dyslexic poets...
write inverse! [tongue]
 
Hey, Thanks for the responce, but please read the beginning of the post too. I've already tried Left() right, mid, and even substr(). None of these work withing Microsoft query for excel 2003 in any context that I have tried so far. If you could open excel and go to DATA-import external data-New database query and try a few of these you should see the problem I am running into.

This is the exact code I am using with the various functions I mentioned and none work even in this basic query:
Select left(table.field, 2) from table
 
Do as Skip suggests and post the all code you are using and database your accessing (Access, Oracle...)




Stubnski

Humans are good students. God created misery, we created computers.
 
WHERE have you tried these functions ??? in the design view of MSQuery ?? in the SQL view ?? are you writing code ?? Please answer the clarification questions you are asked if you want help...
 
I have tried both the gui and the sql editor and neither seem to work. The data source is a flat file called cisam using it's own custom made odbc driver. After reading the above post I'm starting to think the issue is comming from teh data source. Is this possible? It seems strange to me since this function is really in MS Query.
 


SQL syntax DOES often vary with the data source.

As previously stated, string functions used in MS Query but referencing Oracle or DB2 databases, use the Substr function, while SQL referencing MS Access or MS Excel use the Left, Mid and Right functions.

You might give the ststring function a try.

Skip,

[glasses] [red]Be Advised![/red] A man who jumps from a bridge in Paris, is…
INSANE! [tongue]
 
What is the syntaxt for ststring? ie. ststring(field,1,1)

You know what the strange thing is? Left, mid, and right all work if I use Access to query the same data. In this instance I need to use excel though. :(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top