日期:2014-05-17  浏览次数:20413 次

求救存储过程拼接问题
兄弟们,我有一个查询现在要移植到存储过程当中,代码为:
ALTER PROCEDURE [dbo].[test]
  @myWord nvarchar 
AS
DECLARE @tellMe VARCHAR(8000)
BEGIN
  -- routine body goes here, e.g.
  -- SELECT 'Navicat for SQL Server'
set @tellMe='SELECT top 5 * from news WHERE content LIKE('%'+@myword+'%')';
EXEC(@tellMe);
END
但始终报错:
数据类型varchar在modulo运算符中不兼容。
哪位朋友能帮我?

------解决方案--------------------
ALTER PROCEDURE [dbo].[test]
@myWord nvarchar (4000)
AS
DECLARE @tellMe VARCHAR(8000)
BEGIN
-- routine body goes here, e.g.
-- SELECT 'Navicat for SQL Server'
set @tellMe='SELECT top 5 * from news WHERE content LIKE(''%'+@myword+'%'')';
EXEC(@tellMe);
END

------解决方案--------------------
SQL code
ALTER PROCEDURE [dbo].[test] @myWord NVARCHAR
 AS 
     DECLARE @tellMe VARCHAR(8000)
     BEGIN
   -- routine body goes here, e.g.
   -- SELECT 'Navicat for SQL Server'
         SET @tellMe = 'SELECT top 5 * from news WHERE content LIKE(''%''+@myword+''%'')' ;
             --PRINT @tellMe
         EXEC(@tellMe) ;
     END

------解决方案--------------------
up7锅