Search code examples
sql-servert-sqlstored-proceduressqldatatypes

The text, ntext, and image data types are invalid for local variables. after it's casting


I have one stored procedure for getting job info. I cast ntext to nvarchar(max) but still getting error like :

Msg 2739, Level 16, State 1, Line 5
The text, ntext, and image data types are invalid for local variables.
Msg 2739, Level 16, State 1, Line 7
The text, ntext, and image data types are invalid for local variables.
Msg 2739, Level 16, State 1, Line 8
The text, ntext, and image data types are invalid for local variables.

here is my stored procedure :

ALTER PROCEDURE [dbo].[GetJobInfo]
    (
    @jobId int,
    @subject text OUTPUT,
    @plainText1 nvarchar(max) OUTPUT,
    @ToUser text OUTPUT,
    @Cc text OUTPUT,
    @templateID int OUTPUT
    )
AS
BEGIN
    SET NOCOUNT ON

    SELECT TOP 1 @subject = p.[Title],
        @plainText1 = CONVERT(NVARCHAR(max),p.[Body]),
        @ToUser =p.[ToUser],
        @Cc =p.[Cc],
        @templateID =p.[template_id]
        FROM [tbl_Email_master] p INNER JOIN
        [Jobs] j ON p.[Id] =
        j.[PreparedEmailID]
        WHERE j.[JobID] = @jobId
    RETURN
END

What's going wrong here.please help me...


Solution

  • You have parameters of type TEXT (@ToUser, @Cc...), change them to VARCHAR(MAX) or NVARCHAR(MAX) accordingly to the values they are gonna hold, in the SP parameters definition. For emails, it's probably gonna be VARCHAR(MAX).

    TEXT, NTEXT and IMAGE are gonna be deprecated, refrain from using it from now on and try to update it whenever you see it on code.