A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Running & Setting Up Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Convert column Data Type



 
 
Thread Tools Display Modes
  #1  
Old July 15th, 2008, 03:59 PM posted to microsoft.public.access.queries
Alastair MacFarlane
external usenet poster
 
Posts: 12
Default Convert column Data Type

Dear Group,

I have 2 tables with the following schema:

Table A:
ID (Integer)
LinkID (String)

Table B:
ID (Integer)
Ref (Long)

I would like to join Table A == LinkID == Ref == Table B, but cannot
because one is a String and the Other is a Long.

How can I convert and join all in one query without having to create a
secondary intermediary query with a field like "" & Ref?

Thanks again.

Alastair MacFarlane
  #2  
Old July 15th, 2008, 04:11 PM posted to microsoft.public.access.queries
Allen Browne
external usenet poster
 
Posts: 11,706
Default Convert column Data Type

If you type directly into SQL View of the query, you can typecast the field.

Something like this:

SELECT A.*, B.*
FROM A INNER JOIN B
ON CLng(Val(Nz(A.LinkID,"0"))) = B.Ref;

Explanation:
- CLng() casts to Long, so it matches the Ref.
- Val() converts string to number (and copes with non-numeric values.)
- Nz() is needed because Val() can't handle nulls.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Alastair MacFarlane" wrote
in message
...
Dear Group,

I have 2 tables with the following schema:

Table A:
ID (Integer)
LinkID (String)

Table B:
ID (Integer)
Ref (Long)

I would like to join Table A == LinkID == Ref == Table B, but cannot
because one is a String and the Other is a Long.

How can I convert and join all in one query without having to create a
secondary intermediary query with a field like "" & Ref?

Thanks again.

Alastair MacFarlane


  #3  
Old July 17th, 2008, 10:06 AM posted to microsoft.public.access.queries
Alastair MacFarlane
external usenet poster
 
Posts: 12
Default Convert column Data Type

Allen,

Sorry to take so long to say thank you for your time. I will try out your
suggestion and come back to the group if I have any further questions.

Thanks.

Alastair

"Allen Browne" wrote:

If you type directly into SQL View of the query, you can typecast the field.

Something like this:

SELECT A.*, B.*
FROM A INNER JOIN B
ON CLng(Val(Nz(A.LinkID,"0"))) = B.Ref;

Explanation:
- CLng() casts to Long, so it matches the Ref.
- Val() converts string to number (and copes with non-numeric values.)
- Nz() is needed because Val() can't handle nulls.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Alastair MacFarlane" wrote
in message
...
Dear Group,

I have 2 tables with the following schema:

Table A:
ID (Integer)
LinkID (String)

Table B:
ID (Integer)
Ref (Long)

I would like to join Table A == LinkID == Ref == Table B, but cannot
because one is a String and the Other is a Long.

How can I convert and join all in one query without having to create a
secondary intermediary query with a field like "" & Ref?

Thanks again.

Alastair MacFarlane



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.