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.
| Author |
Topic |
|
mcupryk
Yak Posting Veteran
91 Posts |
Posted - 2011-01-25 : 21:44:51
|
| SELECT TOP 100[UserNameID] as ViewerUserNameID, ----- table tbl_ProfileViews[ViewUserNameID] as ViewedUserNameID, ----- table tbl_ProfileViews[TimeStamp] as ViewedDate, ----- table tbl_ProfileViews[PhotoID], ----- table tbl_Photos[ProfileID], ----- table tbl_Photos[p_Primary] ----- table tbl_PhotosViewerUserNameID ViewedUserNameID ViewedDate PhotoID ProfileID p_Primary31 44 2011-01-24 17:22:50.023 40 31 031 44 2011-01-24 17:22:50.023 41 31 031 44 2011-01-24 17:22:50.023 42 31 031 44 2011-01-24 17:22:50.023 43 31 031 44 2011-01-24 17:22:50.023 44 31 031 44 2011-01-24 17:22:50.023 47 31 145 44 2011-01-20 11:36:12.940 50 45 147 44 2011-01-20 11:34:24.320 52 47 1I need to get the latest date and the query should return31 44 2011-01-24 17:22:50.023 47 31 145 44 2011-01-20 11:36:12.940 50 45 147 44 2011-01-20 11:34:24.320 52 47 1I need the latest time and one instance of ViewerUserNameID============================================EXEC @return_value = [dbo].[prc_ProfileViews_SelectByUserName]@ViewedUsernameID = 44,@FromDate = N'12/15/201===============================================ALTER PROCEDURE [dbo].[prc_ProfileViews_SelectByUserName]( @ViewedUsernameID int, @FromDate DATETIME = NULL)ASSELECT TOP 100[UserNameID] as ViewerUserNameID, ----- table tbl_ProfileViews[ViewUserNameID] as ViewedUserNameID, ----- table tbl_ProfileViews[TimeStamp] as ViewedDate, ----- table tbl_ProfileViews[PhotoID], ----- table tbl_Photos[ProfileID], ----- table tbl_Photos[p_Primary] ----- table tbl_PhotosFROM tbl_ProfileViews INNER JOIN tbl_Photos ON tbl_Photos.ProfileID = tbl_profileViews.UserNameIDWHERE tbl_ProfileViews.ViewUserNameID = @ViewedUsernameID AND (@FromDate IS NULL OR (([TimeStamp] >= @FromDate)AND [TimeStamp] = (SELECT MAX([TimeStamp]) FROM tbl_ProfileViews A where A.UserNameID = tbl_profileViews.UserNameID)))ORDER BY [TimeStamp] DESCAny help would be awesome. |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|
|