select * from table_name a where a.name=[入参]如果,想实现 [入参] 为空时,查询出所有的记录;[入参] 为定值时,查询出输入值的相应记录。请问,能否实现,where条件后该如何修改?

解决方案 »

  1.   

    select * from table_name a where a.name in (&入参)  ______________取的是定值
      

  2.   


    if not object_id('Tempdb..T_20081010') is null
    drop table T_20081010
    Go
    Create table T_20081010([ID] int,[S_ID] nvarchar(1),[P_ID] nvarchar(10))
    Insert T_20081010
    select 1,'a','2009-02-00' union all
    select 2,'a','2009-02-28' union all
    select 3,'b','2009-01-28' union all
    select 4,'b','2009-01-25' union all
    select 5,'b','2009-02-27' union all
    select 6,'b','2009-02-26'
    Go
    --Select * from T_20081010 declare @P int 
    set @P=''
    select * from T_20081010
    where (case  when (id=@p) then  1  when @p='' then 1  else 0 end)=1 
      

  3.   

    有好几个月没有来CSDN 了  没有orcle环境  用MS sqlserver  帮你实现一下 
      

  4.   

    select * from table_name a where a.name=decode(param1,null,a.name,param1);
    其中param1为参数!
      

  5.   

    select * from table_name a where a.name like '%$入参%'
      

  6.   

    请问怎么加$这个符号select * from table_name a where a.name=decode(param1,null,a.name,param1);