Excel 2010 & ms query...concatenate two fields?

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

Hi All!

I have what appears to be a simple query, only MS Query doesn't seem to like it too much. I'm trying to query a DB2 data source. I could do it just fine in Excel 2003 but we've "downgraded" to 2010 and now simple stuff doesn't work.

The following seems to generate a syntax error. Can someone help me?

([LOCN_PHY_POST_CDE] & If(isnull([LOCN_PHY_POST_EXT]),,'-' & [LOCN_PHY_POST_EXT]) as ZIP4

I've even tried this and get a syntax error :(

[LOCN_PHY_POST_CDE] & [LOCN_PHY_POST_EXT]

Is there something funky about "&" in Ms Query 2010? Jet?

TIA!

User avatar
HansV
Administrator
Posts: 78857
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel 2010 & ms query...concatenate two fields?

Post by HansV »

Try changing

Code: Select all

If(isnull([LOCN_PHY_POST_EXT]),,'-' & [LOCN_PHY_POST_EXT]) 
to

Code: Select all

IIf(IsNull([LOCN_PHY_POST_EXT]),'','-' & [LOCN_PHY_POST_EXT]) 
This works for me with Access; I can't test with DB2.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

Thanks Hans, but unfortunately this has to be in Excel :(

I'd settle for being able to do this: [LOCN_PHY_POST_CDE] & [LOCN_PHY_POST_EXT]
but even something simple like this generates an error, which is why I think something changed in 2010.

User avatar
HansV
Administrator
Posts: 78857
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel 2010 & ms query...concatenate two fields?

Post by HansV »

I did mean MS Query in Excel but with an Access database as record source. I cannot test with a DB2 database as record source.
What happens if you use + instead of & ?
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

+ generates an error too.

MS query doesn't like the [ ] either. I'm guessing this is a jet problem? grrrr.

This is the exact error: incorrect column expression: '['

It does work quite perfectly in Access.
Last edited by Cecilia on 01 Aug 2012, 16:44, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78857
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel 2010 & ms query...concatenate two fields?

Post by HansV »

Sorry, since I don't have access to a DB2 database I can't help you with this.
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

No prob, Hans, I appreciate the attempt :)

User avatar
HansV
Administrator
Posts: 78857
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Excel 2010 & ms query...concatenate two fields?

Post by HansV »

Cecilia wrote:This is the exact error: incorrect column expression: '['.
What if you omit the square brackets:

LOCN_PHY_POST_CDE & LOCN_PHY_POST_EXT

or

LOCN_PHY_POST_CDE + LOCN_PHY_POST_EXT
Best wishes,
Hans

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

Neither of those options works. I'm fairly certain at this point it's some sort of driver or jet issue, I just need to figure out which one, 'cause IT doesn't believe there is a problem (as usual).

User avatar
kdock
5StarLounger
Posts: 723
Joined: 21 Aug 2011, 21:01
Location: The beautiful hills of Western North Carolina

Re: Excel 2010 & ms query...concatenate two fields?

Post by kdock »

Cecilia wrote:The following seems to generate a syntax error. Can someone help me?

([LOCN_PHY_POST_CDE] & If(isnull([LOCN_PHY_POST_EXT]),,'-' & [LOCN_PHY_POST_EXT]) as ZIP4
This may be a stupid question (as I'm not all that familiar with MS Query), but is there a missing end paren in the "If(isnull([LOCN_PHY_POST_EXT])),, " (and so on...)?

Just a thought...?
Kim
"Hmm. What does this button do?" Said everyone before being ejected from a car, blown up, or deleting all the data from the mainframe.

User avatar
Cecilia
StarLounger
Posts: 89
Joined: 19 Feb 2010, 16:56
Location: San Francisco, Alameda, CA

Re: Excel 2010 & ms query...concatenate two fields?

Post by Cecilia »

Hi Kim,

No such thing as a stupid question. But right now I'm just trying to get LOCN_PHY_POST_CDE & LOCN_PHY_POST_EXT to work, and it has no paren or brackets, or anything else. :-/

Thanks :)