SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


getting in error in using sp_executesql like Procedure expects parameter '@statement' of type...


getting in error in using sp_executesql like Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'

Author
Message
suhailquadri
suhailquadri
SSC-Enthusiastic
SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)

Group: General Forum Members
Points: 107 Visits: 86
I have a stored procedure of this type:

ALTER PROCEDURE INSERT_FLAT_DETAILS
@TABLENAME VARCHAR(50),
@VALUE VARCHAR(1) OUT
AS
BEGIN

DECLARE @SQL VARCHAR(1000)
DECLARE @VALUE1 VARCHAR(10)
SET @SQL = N'SELECT @VALUE1 = COUNT(*) FROM '+ @TABLENAME
exec sp_executesql @SQL,N'@VALUE1 VARCHAR(10) OUTPUT',@VALUE1 OUTPUT
print @sql
print @value1
END

when ever i am executing this with this values like 'tablename','0' ,
it is giving error like
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

can any body help me in solving this. thanks in advance.
Kenneth Wilhelmsson
Kenneth Wilhelmsson
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7015 Visits: 699
You're using the wrong datatype...

From BOL:
[ @stmt = ] stmt
Is a Unicode string that contains a Transact-SQL statement or batch. stmt must be either a Unicode constant or a variable that can be implicitly converted to ntext. More complex Unicode expressions, such as concatenating two strings with the + operator, are not allowed. Character constants are not allowed. If a constant is specified, it must be prefixed with an N. For example, the Unicode constant N'sp_who' is valid, but the character constant 'sp_who' is not. The size of the string is limited only by available database server memory.
-- end BOL --

Change this row:
DECLARE @SQL VARCHAR(1000)
to
DECLARE @SQL NVARCHAR(1000)

/Kenneth



suhailquadri
suhailquadri
SSC-Enthusiastic
SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)SSC-Enthusiastic (107 reputation)

Group: General Forum Members
Points: 107 Visits: 86
thanks a lot for giving help so early.
i am very kindfull to you.
it is executing properly with out any issues.
thnx dude..
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search