在sql里面,那些单引号如何看比较好啊,下面的这个sql存储过程里的单引号看得我头都晕了,有什么比较好的方法理解吗?
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [bookconditionsearch]
(@classfy   [varchar](50),
 @type  [varchar](10),
 @content  [varchar](50),  
 @mode      [int]
 )
AS
begin
 declare @sql nvarchar(1000) --生成的sql语句 
if @classfy=''所有书刊''
 begin
if @mode=1
begin
set @sql=''select * from books where ''+@type+'' like ''''''+@content+''%''''''
exec sp_executesql @sql
end else
begin
set @sql=''select * from books where ''+@type+'' like ''''%''+@content+''%''''''
exec sp_executesql @sql
end
 end
else
 begin
if @mode=1
begin
set @sql=''select * from books where bookclassfy=''''''+@classfy+'''''' and ''+@type+'' like ''''''+@content+''%''''''
exec sp_executesql @sql
end
else
begin
set @sql=''select * from books where bookclassfy=''''''+@classfy+'''''' and ''+@type+'' like ''''%''+@content+''%''''''
exec sp_executesql @sql
end
 end
end

END

解决方案 »

  1.   

    这么大段都放在字符串里面了。出了最外面的两个,其它的都是两个看作一个。或者为了阅读,copy到新窗口,用'替换''
      

  2.   

    为什么要把这些语句放在sql里呢?
    还不如在C#里拼字符串。
    用实体类封装之后就没引号了。
      

  3.   


    http://topic.csdn.net/u/20090227/16/9f795a88-45b5-47c7-b68e-a83ae0d74fd8.html
      

  4.   

    单引号表示字符 双引号表示变量
    @mode 表示变量exec sp_executesql @sql 表示执行存储过程 sp_executesql 并赋予参数@sql
      

  5.   

    begin
     end
    相当于
    {
    }
      

  6.   

    分清是字符串还是变量后在慢慢分析,多看就有经验了。另外sql中的N后跟的十有八九是一段字符串.
      

  7.   


    set @sql=''select * from books where ''+@type+'' like ''''''+@content+''%'''''' 
    (select * from books where @type like @content%)set @sql=''select * from books where ''+@type+'' like ''''%''+@content+''%''''''
    (select * from books where @type like %@content%)set @sql=''select * from books where bookclassfy=''''''+@classfy+'''''' and ''+@type+'' like ''''''+@content+''%''''''
    (select * from books where bookclassfy=@classfy and @type like @content%)set @sql=''select * from books where bookclassfy=''''''+@classfy+'''''' and ''+@type+'' like ''''%''+@content+''%''''''
    (select * from books where bookclassfy=@classfy and @type like %@content%)
      

  8.   

    你看错了吧,"应该是两个单引号的吧,在sql存储过程或查询工具中,是不允许双引号的吧
      

  9.   

    set @sql=''select * from books where ''+@type+'' like ''''''+@content+''%'''''' 
    (select * from books where @type like @content%) set @sql=''select * from books where ''+@type+'' like ''''%''+@content+''%'''''' 
    (select * from books where @type like %@content%) set @sql=''select * from books where bookclassfy=''''''+@classfy+'''''' and ''+@type+'' like ''''''+@content+''%'''''' 
    (se…。。崩溃了。。
      

  10.   

    把代码放到Vs里 。
     up
      

  11.   

    两个单引号连写是 T-SQL 单引号的转义
      

  12.   

    支持代码!
    main
    {
    string 支持代码=“给我积分”!
    }