Click here to Skip to main content
16,022,368 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello I have a query below. I am trying to show 7 days in 14 rows which means that each day should have 2 rows. which works fine

SQL
SELECT  t.*
FROM    Calender AS t
        CROSS JOIN (VALUES (1), (2)) AS Number 


However, when I Left Join with another table then each day will multiply by 2 again so becomes 4 rows

SQL
left outer join (
                                SELECT  distinct
                                        CONVERT(VARCHAR(10), [DateTime], 120) as StampDate
                                        ,convert(varchar(9), [DateTime], 108) AS StampTime
                                        ,x.InOut
                                        ,x.UserID
                                FROM [FTDP].[dbo].[Transaction] x
                                INNER join [FTDP].[dbo].[UserMapping] c
                                    on x.userid = c.userid
                                        and c.DomainId = @DomainId
                                ) x on A.date_id = x.StampDate
) 
ORDER BY 


is there another way to display 14 rows and that does not multiply when I left join?
Posted
Updated 15-Oct-14 12:36pm
v3
Comments
Maciej Los 15-Oct-14 15:31pm    
Not clear! PLease, improve question and post sample data.
[no name] 15-Oct-14 15:38pm    
As Maciej allready posted: Not clear.
j snooze 15-Oct-14 17:48pm    
why not just add DISTINCT or a GROUP BY to your query?
Maciej Los 15-Oct-14 18:38pm    
Try to change the order of queries. Firstly use query to get data from transaction and usermapping tables, then cross join values 1 and 2.
jagadeeshkumar.tangudu 17-Oct-14 2:22am    
Second query is not clear.Can you repost whole query.

1 solution

T = calendar
Number = (1 & 2)
X = inner query

And your join
A.date_id = x.StampDate
where did A come from , this should not even run let alone return records!
 
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