Click here to Skip to main content
15,921,716 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends...

i have two table as follows


CSS
Table  name : Pds_1
valid   empcode shift   edatetime               solid       gplsolid
1       u1      B       2014-08-01 10:23:00.000 25.00000    32.00000
2       u1      B       2014-08-01 10:25:00.000 36.00000    98.00000
3       u1      A       2014-08-01 10:30:00.000 2.00000     65.00000
4       u1      A       2014-08-01 10:24:00.000 23.00000    654.00000
5       u1      C       2014-08-01 10:45:00.000 5.00000     4.00000
6       u1      C       2014-08-01 10:55:00.000 5.00000     4.00000


Table Name : Pds_2
valid   emp shift   edatetime               slurrydensity   caustic     ratio
1       u1  C       2014-08-01 10:24:00.000 5.00000         6.00000     7.00000
2       u1  C       2014-08-01 10:25:00.000 5.00000         2.00000     54.00000
3       u1  B       2014-08-01 01:34:00.000 5.00000         6.00000     5.00000
4       u1  A       2014-08-01 08:35:00.000 6.00000         5.00000     4.00000


and i want to get all entries from pds_1 and pds_2 tables. i used full outer join as follows


SQL
select p1.shift as p1,p1.gplsolid,p1.solid,
p2.shift as p2,p2.caustic,p2.ratio,p2.slurrydensity from pds_1 p1 full outer join pds_2 p2
on p1.shift = p2.shift
where CONVERT(varchar,p1.edatetime,103) in (convert(varchar,@date,103))
and CONVERT(varchar,p2.edatetime,103) in (convert(varchar,@date,103))


but it gives repeated row that i don't want


PDS
"Wagon Bauxite
% Moisture" "Ball Mill Feed
+1 inch
Max:15%" "Ball Mill Feed
Moist
%" "Ball Mill Product
TPH
m3/hr" "Ball Mill Product
Ball Mill No." "Ball Mill Product
% Solid" "Ball Mill Product
Density"
C 4.00 5.00 C 6.00 7.00 5.00
C 4.00 5.00 C 2.00 54.00 5.00
C 4.00 5.00 C 6.00 7.00 5.00
C 4.00 5.00 C 2.00 54.00 5.00
B 32.00 25.00 B 6.00 5.00 5.00
A 65.00 2.00 A 5.00 4.00 6.00
B 98.00 36.00 B 6.00 5.00 5.00
A 654.00 23.00 A 5.00 4.00 6.00
Posted
Comments
Richard Deeming 11-Aug-14 9:51am    
Both tables have two rows for shift C / employee u1 on 1st August.

Unless there is some other means of determining which row from Pds_1 matches which row from Pds_2, both rows from the first table will match to both rows from the second table, giving you four rows in the output.

1 solution

1) declare @date as DATE,
2) do not convert dates to varchar! character strings do not compare as you might think.
3) if you need to compare date to date convert the two dates to DATE then use equal:
SQL
where CAST(p1.edatetime AS DATE) = @date
   and CAST(p2.edatetime AS DATE) = @date
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900