Question : OCS 2007 Archiving Query

I would like to run the following query;
SELECT * from LcsLog.dbo.Messages, LcsLog.dbo.Users where LcsLog.dbo.Users.UserId =
LcsLog.dbo.Messages.ToId and LcsLog.dbo.Users.UserUri = '[email protected]'

but instead of the it saying FromID and ToID, i would like it to use the UserUri instead.  

Answer : OCS 2007 Archiving Query

You need to replace "...other columns..." with the names of the other columns you want to include in the results.  Technically you could just add a "*" (meaning all columns). But a) that is really bad form and b) depending on how you're using it may not work since the column names won't be unique.  But try it anyway, just to see.

SELECT t.UserUri AS ToUser, f.UserUri AS FromUser,  *
FROM   LcsLog.dbo.Messages m
           INNER JOIN LcsLog.dbo.Users t ON t.UserId = m.ToId
           INNER JOIN LcsLog.dbo.Users f ON f.UserId = m.FromId
WHERE  t.UserUri = '[email protected]'

Unfortunately, I'm not very familiar with the schema of those tables. If you could post a screen shot of the table columns, I could be more specific.  
Random Solutions  
 
programming4us programming4us