473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Joining tables with different data types on the common field

2
Is there a way to join 2 tables where the 2 fields on which the tables joined are of different data types(char and varchar)?I tried with CONVERT but is does not give the desired output.

My requirement is to get the minimum (earliest) Posted date along with two other fields.But when i join the two fields I get the duplicate records as well.

Following is my query.


---------------------------------------------------------------------------------------------------------
SELECT DISTINCT RMS_T_CV_SENT_INFORMATION.ReqRefID,
T.FirstName,MIN(RMS_T_CV_SENT_INFORMATION.CVPosted Date) AS Posteddate FROM
RMS_T_CV_SENT_INFORMATION JOIN

(SELECT DISTINCT RMS_T_CV_INFORMATION.FirstName,RMS_T_CV_INFORMATIO N.CVRefID
FROM RMS_T_CV_INFORMATION GROUP BY RMS_T_CV_INFORMATION.FirstName,RMS_T_CV_INFORMATIO N.CVRefID)AS T
ON CONVERT(varchar(11),SUBSTRING(T.CVRefID,1,11))=CON VERT(varchar(11),SUBSTRING(RMS_T_CV_SENT_INFORMATI ON.CVID,1,11))

GROUP BY RMS_T_CV_SENT_INFORMATION.ReqRefID,T.FirstName

ORDER BY RMS_T_CV_SENT_INFORMATION.ReqRefID


---------------------------------------------------------------------------------------------------------

In the above ,the RMS_T_CV_SENT_INFORMATION.CVID and RMS_T_CV_INFORMATION.CVRefID are the related fields but one is of varchar(15) and other field is of Char(15).
I m sorry ,if this is too lenthy and confusing.

thanks in advance.
Jul 25 '07 #1
4 11181
ilearneditonline
130 Expert 100+
Not knowing really what your data looks like and I am confused why you are joining to recordsets. Can you give some additional details, maybe some comments on why u r doing what u r doing.
Jul 25 '07 #2
hi
you must create ' views' or 'stored procedure with dataset returning' for each section of your select statement then you can use cast() function for changing the type of your output column in that view. then join that views or storedprocedures in anaother select statement to output the dataset you need.
Jul 25 '07 #3
ilearneditonline
130 Expert 100+
you must create ' views' or 'stored procedure with dataset returning' for each section of your select statement then you can use cast() function for changing the type of your output column in that view. then join that views or storedprocedures in anaother select statement to output the dataset you need.
Actually, if you are doing it in a stored procedure you could create temp table that holds everything and output that data.

Something along this lines...

Expand|Select|Wrap|Line Numbers
  1.  DECLARE @Temp TABLE( 
  2. ,CVID varchar(11)
  3. ,ReqRefId int
  4. ,firstname varchar(20)
  5. ,posteddate datetime)
  6.  
  7. INSERT @Temp(CVID, ReqRefId,posteddate)
  8. SELECT DISTINCT CAST(SUBSTRING(CVID,1, 11) AS varchar(11)), ReqRefID, MIN(CVPostedDate)
  9. FROM RMS_T_CV_SENT_INFORMATION
  10.  
  11. UPDATE @Temp
  12. SET firstname=a.FirstName
  13. FROM RMS_T_CV_SENT_INFORMATION a
  14. INNER JOIN @Temp b
  15. ON b.CVID=a.CVRefID
  16.  
  17. SELECT * FROM @Temp
  18.  
Jul 25 '07 #4
herath
2
Thanks for the replies.I tried creating stored procedures but that doesn't filter the correct records either.

Requirement: Get the minimum posted date ,with the CV holder's name per Requirement Id(ReqRefId)

Fields from RMS_T_CV_SENT_INFORMATION table :ReqRefID,CVPostedDate

Fields from RMS_T_CV_INFORMATION table :FirstName

Common fields are:RMS_T_CV_INFORMATION.CVRefID(char 15) and RMS_T_CV_SENT_INFORMATION.CVID(varchar 15)

---------------------------------------------------------------------------------------------------------------
SELECT DISTINCT RMS_T_CV_SENT_INFORMATION.ReqRefID,RMS_T_CV_INFORM ATION.FirstName, MIN(RMS_T_CV_SENT_INFORMATION.CVPostedDate) AS PostedDate

FROM RMS_T_CV_SENT_INFORMATION
INNER JOIN RMS_T_CV_INFORMATION ON
CONVERT(char(15),RMS_T_CV_INFORMATION.CVRefID)=CON VERT(char(15),RMS_T_CV_SENT_INFORMATION.CVID)
GROUP BY RMS_T_CV_SENT_INFORMATION.ReqRefID,RMS_T_CV_INFORM ATION.FirstName,RMS_T_CV_SENT_INFORMATION.CVPosted Date
ORDER BY RMS_T_CV_SENT_INFORMATION.ReqRefID

-------------------------------------------------------------------------------------------------------------------

There are 5 other tables too involved in the query with same data mismatch issues.But at least if this part works i could apply the same theory for those as well.The database contains no relationships or primary keys.(I am sorry, it's the worst database created by a fresher).
Jul 26 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Dave M | last post by:
All I've got a database that keeps track of sales of widgets. Each company that belongs to my organiztion is to report their widget sales or no sales every month. There are several different...
2
by: James | last post by:
Can anyone please shed some light on the following... I have a framework that uses dynamically created tables, named using an incremental "attribute set ID", as follows: attrdata_1 attrdata_2...
3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
9
by: Koen | last post by:
Hi all, My application uses a lot of lookup tables. I've splitted the frontend (forms, reports, etc) from the backend (data). The database has around 10 different users. The values in the...
3
by: Stephen | last post by:
It is possible to relate queries to tables, right? It seems logical but when I try to match my queries to any of the tables or even to each other it gives me a blank relationship. What could I...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
3
by: Reader | last post by:
Hello all, I am joining two tables in a query and the output should be all those records where two fields in table1 match two corresponding fields in table2. I joined the tables using both...
10
by: Robert | last post by:
How do you get an accurate count of the number of records returned from a query when using linked tables. I have an access 2003 database as a front end to another access 2003 database that...
2
by: nkechifesie | last post by:
I have created 9 tables in access via visdata and need to create another table joining all these tables. I have used the query in visdata to do this but it gives me an outrageous view. I have entered...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.