我的数据库是SQL2000,建了一个表,表里面的数据类型都是nvarchar型的。
我用下面这条语句可以直接读出数据select * from t_me_solder_condition where Compon_Name like N'电容'
但用过程传变量就不行了,读不出来值:declare @Section varchar(20),@Name varchar(20), @PN varchar(20)
set @Section=N'%'
set @Name=N'电容'
set @PN=N'%'
select Section,Compon_Name as 物料类型,PN as 料号,Peak_Tmp,Time_Liqui as Time_above_Liquid_217,IS_MSI_Proc as MSI制程,Note as 备注 from T_ME_Solder_Condition
where Section like  @Section and Compon_Name like @Name and PN like @PN;
不知道是不是编码的问题。我的数据库装的是繁体版的,表定序设的是China_CI_PRC_AS
另外,我要调过程的时候,传的参数怎么把它前面加个“N”

解决方案 »

  1.   


    --用nvarchar字段
    declare @Section nvarchar(20),@Name nvarchar(20),    @PN nvarchar(20)
    set @Section=N'%'
    set @Name=N'电容'
    set @PN=N'%'
    select Section,Compon_Name as 物料类型,PN as 料号,Peak_Tmp,Time_Liqui as Time_above_Liquid_217,IS_MSI_Proc as MSI制程,Note as 备注
        from T_ME_Solder_Condition
            where Section like  @Section and Compon_Name like @Name and PN like @PN;
      

  2.   

    where Section like  @Section and Compon_Name like @Name and PN like @PNwhere Section like  @Section + @Name + @PN
      

  3.   

    where Compon_Name like @Section + @Name + @PN楼主是这个意思么?还是?
      

  4.   


    declare @Section nvarchar(20),@Name nvarchar(20),@PN nvarchar(20)
    set @Section=N'%'
    set @Name=N'电容'
    set @PN=N'%'
    select Section,Compon_Name as 物料类型,PN as 料号,Peak_Tmp,Time_Liqui as Time_above_Liquid_217,IS_MSI_Proc as MSI制程,Note as 备注
        from T_ME_Solder_Condition
            where Section like  @Section and Compon_Name like @Name and PN like @PN;/**1、如果楼主的section没有%这种字符串,那么不会有结果集;
    2、如果楼主的PN没有%这种字符串,那么不会有结果集;
    3、可以将 @section 和 @PN 赋值为 '%%',或者赋值为NULL,where条件改为 isnull(@..,'%%')