gpt4 book ai didi

sql - 如何在 sql server 2008 中声明时在游标中使用 if 条件?

转载 作者:行者123 更新时间:2023-12-04 12:49:55 28 4
gpt4 key购买 nike

我有如下查询

Declare Cur_1 cursor for 

if @EmployeeId <> is not null
begin
select EmployeeID from tbl_Employee where EEmployeeStatus='Active' and EmployeeID = @EmployeeId
end
else
begin
select EmployeeID from tbl_Employee where EEmployeeStatus='Active'
end

Open Cur_1

Fetch next from Cur_1 into @EmpId
While @@FETCH_STATUS=0
Begin

end
Close Cur_1
deallocate Cur_1

但它不起作用。它告诉我语法错误。

它在 if 条件下显示语法错误..

请帮帮我......

最佳答案

 if @Feild is not null
begin
Declare your_Cursor_Name cursor for
select Feild1 from Your_table where 1=1
end
else
begin
Declare your_Cursor_Name cursor for
select Feild1 from Your_table where 1=1
end

Open your_Cursor_Name

Fetch next from your_Cursor_Name into @xyz
While @@FETCH_STATUS=0
Begin
`enter code here
end
Close your_Cursor_Name

关于sql - 如何在 sql server 2008 中声明时在游标中使用 if 条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40459501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com