Strange issue.
I have a sql statement that returns a set of rows for a datagrid (which works correctly).
I have the same criteria to get a count of rows in a stored procedure.
My problem is when I get the count from the stored procedure it always returns the number of records, but, the sql statement returns the correct rows, any ideas why that would be different?
(Thanks in Advance)
SQL Statement:
SQL Stored Procedure:
-FYI, what Im trying to do is display an icon that messages are available for this user, if the user flags that the message has been viewed then I don't want to display the icon that they have messages. The stored procedure gives me the count of messages unread for the user (so I can display the icon or not - doesnt work), and the sql statement is for a datagrid of the messages once they click the icon - (it works)
I've beat myself for hours and don't see why
I have a sql statement that returns a set of rows for a datagrid (which works correctly).
I have the same criteria to get a count of rows in a stored procedure.
My problem is when I get the count from the stored procedure it always returns the number of records, but, the sql statement returns the correct rows, any ideas why that would be different?
(Thanks in Advance)
SQL Statement:
Code:
SELECT Messages_Admin.Subject, Messages_Admin.Message,
Messages_Admin.CreatedDate, Messages_Admin.CreatedBy,
Messages_Admin.MsgID
FROM Messages_Admin LEFT OUTER JOIN Messages_Viewed ON Messages_Admin.MsgID = Messages_Viewed.Msg_ID
WHERE (Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.Viewed = 0) AND (Messages_Viewed.[User] = @UserName)
OR (Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.Viewed IS NULL) AND
(Messages_Viewed.[User] IS NULL) OR
(Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.[User] <> @UserName)
SQL Stored Procedure:
Code:
ALTER PROCEDURE [dbo].[MessageCount]
-- Add the parameters for the stored procedure here
@UserName nvarchar,
@Org_ID int,
@Count int output
AS
BEGIN
-- Insert statements for procedure here
SET NOCOUNT ON;
SELECT @Count = COUNT(*)
FROM Messages_Admin LEFT OUTER JOIN
Messages_Viewed ON Messages_Admin.MsgID = Messages_Viewed.Msg_ID
WHERE (Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.Viewed = 0) AND (Messages_Viewed.[User] = @UserName) OR
(Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.Viewed IS NULL) AND (Messages_Viewed.[User] IS NULL) OR
(Messages_Admin.Org_ID = @Org_ID) AND (Messages_Viewed.[User] <> @UserName)
END
-FYI, what Im trying to do is display an icon that messages are available for this user, if the user flags that the message has been viewed then I don't want to display the icon that they have messages. The stored procedure gives me the count of messages unread for the user (so I can display the icon or not - doesnt work), and the sql statement is for a datagrid of the messages once they click the icon - (it works)
I've beat myself for hours and don't see why