0

我不想根据条件/参数显示列我想要的是

if(@SelectFlag==true)
    select name,Address,salary,CreatedBy from employee
else (@UpdateFlag==true)
    select name,Address,salary from employee    
    -- in this case i don't require the column "CreatedBy"

如何根据上述情况进行查询或存储过程..

感谢和问候..

4

4 回答 4

0

这是创建存储过程的示例,也许您只需要一个参数来指示您要做什么

CREATE PROCEDURE procedurenameHere(@EventFlag INTEGER)
AS
    -- @EventFlag
    -- 1 for SELECT
    -- 2 for UPDATE
    IF @EventFlag = 1
        SELECT  name,Address,salary,CreatedBy 
        FROM    employee
    ELSE IF @EventFlag = 2
        SELECT  name,Address,salary, NULL AS CreatedBy 
        FROM    employee
GO

执行:

EXEC procedurenameHere 1
于 2013-02-12T06:47:54.417 回答
0

使用单个=and1而不是true.

if @SelectFlag = 1
  select name, Address, salary, CreatedBy from employee
else
if @UpdateFlag = 1
  select name, Address, salary from employee    
于 2013-02-12T06:48:16.560 回答
0

试试这个

表:emp
列:姓名、地址、工资、creditedBy

declare My_Block
    p_select_flag emp.SelectFlag%type;
    p_updateFlag  emp.UpdateFlag%type;
BEGIN
    select selectFlag into p_select_flag from emp where name='ASIF';
    select update into p_updateFlag from emp where name='ASIF';

IF p_select_flag = 'TRUE' THEN
    select name,Address,salary,CreatedBy from employee;
ELSIF UpdateFlag = 'TRUE' then
    select name,Address,salary from employee;
END IF;

END My_Block
于 2013-02-12T06:59:37.480 回答
0

U 可以在 SP 内部调用带参数并将一个参数作为 FLAG 作为整数传递:

使用 single = 和 1,2 而不是 true。

1 表示选择和 2 表示更新

if @FLAG = 1
  select name, Address, salary, CreatedBy from employee
else
if @FLAG = 2
  select name, Address, salary from employee  
于 2013-02-12T08:39:14.707 回答