|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 15, 2008 3:20 AM
Points: 1,
Visits: 2
|
|
Hi,
I am using dynamic query in stored procedure. while i am trying to execute the SQL Query in the Procedure, i am getting the error 'Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.
Because i have passed the parameter as Varchar in sp_executesql. The parms must be nVarchar. But my issues is, the length of Dynamic SQL Query is more than 4000. nVarchar maximum lenght is 4000.
Please let me know the solution.
my Stored Procedure as,
CREATE procedure Search ( @SearchKeyword Varchar(2000), @Productid varchar(2000), @Type varchar(200), @SQLPerms varchar(5000)
) as Declare @SQL varchar(7000) set @SQL=' This Statement length goes more than 4000.' exec sp_executesql @SQL GO
Appriciate your response asap.
Regards, Vijay
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:18 PM
Points: 38,062,
Visits: 30,359
|
|
you can use exec, since you're not passing parameters in or out of the dynamic SQL
CREATE procedure Search ( @SearchKeyword Varchar(2000), @Productid varchar(2000), @Type varchar(200), @SQLPerms varchar(5000)
) as Declare @SQL varchar(7000) set @SQL=' This Statement length goes more than 4000.' exec (@SQL) GO
Make sure you're checking for SQL injection attempts.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, July 22, 2009 12:37 AM
Points: 1,
Visits: 12
|
|
Sql string should be always either ntext/nvarchar/nchar. So ,please check type of sql query variable as nvarchar()
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:18 PM
Points: 38,062,
Visits: 30,359
|
|
mayank.and.friends (6/10/2009) Sql string should be always either ntext/nvarchar/nchar.
Only necessary when using sp_executesql (which takes nvarchar parameters). Not important when using EXEC. Also, you cannot define a variable of type ntext.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:10 PM
Points: 518,
Visits: 920
|
|
this explains it why mine did not work also.. I had bigint and table data types..
Cheers, John Esraelo
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, May 02, 2013 1:20 PM
Points: 1,235,
Visits: 5,389
|
|
You can also use nvarchar(max) which replaces ntext.
Drew
J. Drew Allen Business Intelligence Analyst Philadelphia, PA
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 3:10 PM
Points: 518,
Visits: 920
|
|
..with possibilities of truncation?
Cheers, John Esraelo
|
|
|
|