Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Joining Datetime fields using Left outer join Post Reply Post New Topic
Author Message
Shan
Newbie
Newbie
Avatar

Joined: 07 Oct 2008
Location: United States
Online Status: Offline
Posts: 4
Quote Shan Replybullet Topic: Joining Datetime fields using Left outer join
     Posted: 07 Oct 2008 at 8:42am
Hi,
I am working in Crystal report ver 9.
I am joining two tables table1 & table2. I am using Left Outer join and joining "id1" in table1 with "id2" in table2. Also i am trying to join "Datetime1" in table1 with "Datetime2" in table2. Actually, here in the outer join condition, i need to check only the Date of "Datetime1" with Date of "Datetime2". How can i check that in the outer join condition in crystal report9?
 
When I outer join these two tables by using "Database Expert > Link" in crystal 9, the out put of the query that i get is as below:
 
select table1.id1. table1.datetime1, table1.field1, table2.field2
from table1
LEFT OUTER JOIN table 2 ON
table1.id1=table2.id2 AND
table1.datetime1 = table2.datetime2
 
But i am not able to convert the datetime field to Date at the Left Outer Join condition. Actually I am expecting the query to be generated as below after Outer joining table1 & table2:
 
select table1.id1. table1.datetime1, table1.field1, table2.field2
from table1
LEFT OUTER JOIN table 2 ON
table1.id1=table2.id2 AND
(CONVERT(Varchar(10), table1.datetime1, 101)=CONVERT(Varchar(10), table2.datetime2, 101))
 
 
"(CONVERT(Varchar(10), table1.datetime1, 101)=CONVERT(Varchar(10), table2.datetime2, 101))"
part in the above query actually checks ONLY the "Date" of table1.datetime1 and table2.datetime2 and NOT "Datetime" of those fields.
 
Is it possible to convert datetime field date into date "ON" the Left Outer Join condition itself (not in the where condition)?
 
Thanks for your help in advance.
 


Edited by Shan - 07 Oct 2008 at 12:02pm
Shan
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 07 Oct 2008 at 2:25pm

It's not possible to do this in the joins in Crystal when working with tables.  I haven't worked in v 9 (went from 8.5 straight to XI) so I'm not exactly sure what the terminology is, but you might be able to add a "command" which is a SQL statement that would get the fields you need from both tables and set up the joins like you want them.

The other way to do this would be to create a formula and use it in the Select Expert.  It would look something like this:

ToText({table1.datetime1}, 'MM/dd/yyyy') = ToText({table2.datetime2}, 'MM/dd/yyyy')

Add this to the Select Expert and select "Is True".  The problem with this method is that this "calculation" probably will be processed by Crystal after it has gathered all the data instead of being processed on the database server.

-Dell

IP IP Logged
Shan
Newbie
Newbie
Avatar

Joined: 07 Oct 2008
Location: United States
Online Status: Offline
Posts: 4
Quote Shan Replybullet Posted: 08 Oct 2008 at 1:29pm
Thanks Dell.
 
I don't think the "Command" is available in ver 9.
I have added the condition in the crystal report formula and it worked fine.
 
Thanks once again.
 
Shan
Shan
IP IP Logged
bowja
Newbie
Newbie
Avatar

Joined: 07 Dec 2009
Location: Australia
Online Status: Offline
Posts: 31
Quote bowja Replybullet Posted: 10 Feb 2014 at 5:46pm
Hi,

I have the same question but believe I do need to use the command function.  I am working in XI.

The datetime fields I wish to join with a full outer join based only on date are
roster_shifts.date and public_holidays.date.

I have not been able to get the syntax down.  Unfortunately my SQL is quite limited (understatement).

Can someone please let me know how such an expression would be written?
If you think you can or think you can't you are right - Paraphrased quote Henry Ford
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum