我要从中选择数据的表:
代码:
if exists(select * from MyTable where ActChildID_FK = @actid_fk)
begin
declare @parentid int, @fnname nvarchar(100)
select @parentid = ActParentID_FK
from MYTabe
where ActChildID_FK = @actid_fk
end
问题是,当ActChildID_FK = 300734
返回ActParentID_FK
的两个值时,我只需要接收一个值,并且我不想更改表中的任何值。
只需使用TOP 1
即可获取单行。查看有关本文的更多详细信息:https://msdn.microsoft.com/en-us/library/ms189463.aspx