Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I have a table which contains some project information. In that table it has a field for the UserId which created the project record, some other irrelevant fields and a LastUpdatedByUserId field, which contains exactly what it says(the last person to update the project record). How could I perform a select/view to get all records which would allow me to return a record for the user who created the record, and then another record with the userId being that of the updatedUserId, with a flag set saying PerformedUpdate? Is it even possible?
Arnold Fribble
Yak-finder General
1961 Posts
Posted - 2001-12-18 : 12:30:36
Like this?
SELECT ProjectRecordId, CreateUserId AS UserId, CONVERT(bit, 0) AS PerformedUpdateFROM ProjectInformationUNION ALLSELECT ProjectRecordId, LastUpdatedByUserId, 1FROM ProjectInformation
Onamuji
Aged Yak Warrior
504 Posts
Posted - 2001-12-18 : 12:39:40
SELECT entries.IDENTITYCOL ID, CASE modes.mode WHEN 1 THEN created.Name ELSE updated.Name END UserName, modes.modeFROM CatalogItems entries INNER JOIN Users created ON entries.CreatorID = created.UserID) INNER JOIN Users updated ON entries.UpdatorID = updated.UserID) CROSS JOIN (SELECT 0 mode UNION SELECT 1 mode) modesORDER BY entries.IDENTITYCOL, modes.mode