当前位置: 代码迷 >> Sql Server >> 喂,说你呢,没错就是你,进来啊解决办法
  详细解决方案

喂,说你呢,没错就是你,进来啊解决办法

热度:29   发布时间:2016-04-27 17:36:38.0
喂,说你呢,没错就是你,进来啊
一个存储过程执行错误:执行列字符列的引号消失.
,代码如下
ALTER   PROCEDURE   goods_pageing
@area   nvarchar(50)= '总站 ',
@provider   nvarchar(50)= '新华书店 '

AS
declare   @strWhere   varchar(100)
declare   @Str   varchar(1000)

set   @strWhere= '   [area]= '[email protected]

SET   @Str= 'select   count(*)   as   total   from   books   where '[email protected]
PRINT   @Str
EXEC   (@Str)
执行结果如下:
****************************************************
      select   count(*)   as   total   from   books   where   [area]=总站
列名   '总站 '   无效。
没有行受影响。
(返回   0   行)
@RETURN_VALUE   =   0
完成   [dbo].[goods_pageing]   运行。
********************************************************
为什么执行结果字符列   area的 ' '单会消失呢
[email protected]   count(*)   from   books   where   [email protected]
则没有错误
有点不解,请知道的帮帮忙


------解决方案--------------------
ALTER PROCEDURE goods_pageing
@area nvarchar(50)= '总站 ',
@provider nvarchar(50)= '新华书店 '

AS
declare @strWhere varchar(100)
declare @Str varchar(1000)

set @strWhere= ' [area]= ' ' '[email protected] + ' ' ' '

SET @Str= 'select count(*) as total from books where '[email protected]
PRINT @Str
EXEC (@Str)

------解决方案--------------------

set @strWhere= ' [area]= ' ' '[email protected]+ ' ' ' '
------解决方案--------------------
ALTER PROCEDURE goods_pageing
@area nvarchar(50)= '总站 ',
@provider nvarchar(50)= '新华书店 '

AS
declare @strWhere varchar(100)
declare @Str varchar(1000)

set @strWhere= ' [area]= ' ' '[email protected]+ ' ' ' ' --这里添加单引号

SET @Str= 'select count(*) as total from books where '[email protected]
PRINT @Str
EXEC (@Str)
  相关解决方案