Alan Warren
asked on
Insert Into TableA... From TableB Left Outer Join
Using SQL Express 2005
I have a table (tblDefaultPic) that contains one record, it is priming table, the data in it is used to create a default record in another table (tblPics) when a new user is created.
The key field in all tables is UserID which is a UniqueIdentifier.
The field UserID definately exists in table (aspnet_users)
Can't quite seem to get my head around this, maybe its getting late, looking for a quick answer if possible, thanks.
This is what I have, but the select returns 0 records, hmmm.
INSERT INTO tblPics ([Filename], FileExtension, Picture, [Size], [Type], Created, Thumb, Album, Active, PrimaryPic, UserID)
SELECT D.[Filename], D.FileExtension, D.Picture, D.[Size], D.[Type], D.Created, D.Thumb, D.Album, D.Active, D.PrimaryPic, @UserID
FROM tblDefaultPic AS D Left OUTER JOIN
aspnet_Users AS U ON D.UserID = U.UserId LEFT OUTER JOIN
tblPics as Px ON D.UserID = Px.UserID
WHERE (Px.UserID IS NULL)AND
(D.UserID IS NULL)
I have a table (tblDefaultPic) that contains one record, it is priming table, the data in it is used to create a default record in another table (tblPics) when a new user is created.
The key field in all tables is UserID which is a UniqueIdentifier.
The field UserID definately exists in table (aspnet_users)
Can't quite seem to get my head around this, maybe its getting late, looking for a quick answer if possible, thanks.
This is what I have, but the select returns 0 records, hmmm.
INSERT INTO tblPics ([Filename], FileExtension, Picture, [Size], [Type], Created, Thumb, Album, Active, PrimaryPic, UserID)
SELECT D.[Filename], D.FileExtension, D.Picture, D.[Size], D.[Type], D.Created, D.Thumb, D.Album, D.Active, D.PrimaryPic, @UserID
FROM tblDefaultPic AS D Left OUTER JOIN
aspnet_Users AS U ON D.UserID = U.UserId LEFT OUTER JOIN
tblPics as Px ON D.UserID = Px.UserID
WHERE (Px.UserID IS NULL)AND
(D.UserID IS NULL)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!
Thank you for the quick response.
Alan ";0)
Thank you for the quick response.
Alan ";0)
ASKER
SELECT D.[Filename], D.FileExtension, D.Picture, D.[Size], D.[Type], D.Created, D.Thumb, D.Album, D.Active, D.PrimaryPic, U.UserID
FROM aspnet_Users AS U Left OUTER JOIN
tblDefaultPic AS D ON U.UserID = D.UserId LEFT OUTER JOIN
tblPics as Px ON U.UserID = Px.UserID
WHERE (Px.UserID IS NULL)AND
(D.UserID IS NULL)
Returns:
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 39CAC0A4-2ACE-45CF-9832-01
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 16A4DAAD-05EC-4E50-9913-02
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL AF1AFE3E-91D7-4BFD-91ED-0D
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL FEEB2322-D400-40E6-86B2-11
NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL C93919C6-7D36-4EF8-94CB-29
Alan