DECLARE @SenderUserName NVARCHAR(50)
DECLARE @ReceiverUserName NVARCHAR(50)
DECLARE @Yesterday DATE

SET @SenderUserName = N'ali'
SET @ReceiverUserName = N'hamid'
SET @Yesterday = DATEADD(DAY , -1 , GETDATE())

SELECT D.MessageID , D.SenderUserName , D.ReceiverUserName , D.MessageDate , D.MessageBudy FROM
(
SELECT     dbo.tblMessagesPrivate.MessageID, dbo.tblUsers.IUserName AS SenderUserName, tblUsers_1.IUserName AS ReceiverUserName, CONVERT(date, 
                      dbo.tblMessagesPrivate.MessageDateTime) AS MessageDate, dbo.tblMessagesPrivate.MessageBudy
FROM         dbo.tblMessagesPrivate INNER JOIN
                      dbo.tblUsers ON dbo.tblMessagesPrivate.SenderID = dbo.tblUsers.IUserID INNER JOIN
                      dbo.tblUsers AS tblUsers_1 ON dbo.tblMessagesPrivate.ReceiverUserID = tblUsers_1.IUserID
)D  WHERE 
D.SenderUserName = @SenderUserName AND
D.ReceiverUserName = @ReceiverUserName AND
d.MessageDate = @Yesterday

