select  a.* from song a
inner join ...附属表1
on ..
inner join ...附属表2
on ..
where songname like '%' + isnull(nullif(@songname,''),songname) + '%'
    and AlbumsName like '%' + isnull(nullif(@AlbumsName,''),AlbumsName) + '%'
    and Composer = isnull(nullif(@Composer),Composer )
    and ...如果 AlbumsName 数据库中值为null 则会出现 AlbumsName is like null 导致数据丢失,如何解决 谢谢~~先在这里谢谢 fcuandy 大哥

解决方案 »

  1.   


    select     a.*   from   song   a 
    inner   join   ...附属表1 
    on   .. 
    inner   join   ...附属表2 
    on   .. 
    where   (@songname is null or songname   like   '%'   +   @songname +   '%') 
            and  (@AlbumsName is null or AlbumsName  like   '%'  +   @AlbumsName +   '%' )
            and  (@Composer is null or Composer   =   @Composer) 
            and   ... 
      

  2.   

    and   isnull(AlbumsName,'')   like   '%'   +   isnull(nullif(@AlbumsName,''),AlbumsName)   +   '%' 
      

  3.   

    谢谢~ happyflystone 的答案似乎还是少数据~~Haiwer 谢谢~