1

I tried to search some post but i got no lucky to find like my scenario:

This is my attempt but no luck.

declare @tb varchar(30)
set @tb = 'newtablename'
declare @sql varchar(30) = 'select * into ' + @tb + ' from tbl_3;'
EXEC  sp_executesql  @sql

it returns an error

Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.

Any suggestions will be appreciated.

Thanks in advance.

1 Answer 1

2

You're declaring your @tb and @sql variables as type varchar(30). The error clearly warns that it expects ntext, nchar, or nvarchar. Also, your @sql string would be truncated at length 30. I would suggest changing your code to the following:

declare @tb nvarchar(30)
set @tb = 'newtablename'
declare @sql nvarchar(255) = 'select * into ' + @tb + ' from tbl_3;'
EXEC  sp_executesql  @sql
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.