Temporary table is not compatible with user-defined type. You should declare your temporary table as user-defined type:
CREATE TYPE dbo.tmp_Messages AS TABLE
(
ID BIGINT,
FirstName VARCHAR(50),
LastName VARCHAR(50),
UserType varchar(50),
SenderID bigint,
IsArchive bit
)
GO
--function declaration
CREATE FUNCTION [dbo].[GetCnt] (
@Status nvarchar(10),
@MsgTempTable dbo.tmp_Messages READONLY
)...
-- table defined in dbo.GetMsgCntData
DECLARE @tmpTable dbo.tmp_Messages;
INSERT INTO @tmpTable(---some actions
SELECT cnt(*) total,
dbo.GetCnt('open', @tmpTable) as opened,
dbo.GetCnt('closed', @tmpTable) as closed
FROM @tmpTable
Please read a good article about table-valued parameters: http://beyondrelational.com