SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to get Primary Key Value if not Present in Foreign Key via Join?


How to get Primary Key Value if not Present in Foreign Key via Join?

Author
Message
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)SSC Guru (97K reputation)

Group: General Forum Members
Points: 97195 Visits: 38988
eligiable (5/4/2014)
Lynn Pettis! The 2nd Query is just for reference, that what I'm trying to get into the results. My main Table is tblGen_Users and UserID is PK, I've tried every logic, I can think; but no luck.


SELECT
A.SignedByUserID,
B.FullName,
COUNT(A.OutletID) AS TotalSignups,
DATENAME(Month, A.SignupDate) AS Month
FROM
dbo.tblGen_Users AS B LEFT OUTER JOIN
--The tblGen_Users contains all the values
dbo.tblMer_Outlet AS A ON B.UserID = A.SignedByUserID
--The tblMer_Outlet contains only the selected values

/* If the values from tblGen_Users are not available in tblGen_Merchant, the missing values must be displayed in the result mentioning 0 under COUNT */

WHERE
(A.SignupDate >= '2014-04-01 00:00:00') AND
(A.SignupDate <= '2014-04-30 23:59:59')
GROUP BY
A.SignedByUserID,
B.FullName,
DATENAME(Month, A.SignupDate)
ORDER BY
B.FullName



I do know that the second query was for reference. My point was that your first query would not return any values from the second table that did not exist in the first table.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search