本文介绍了如果在SQL Server中存在语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一个SQL Server,该SQL Server将一个值分配给保留在if存在语句中的临时值.
但是没有用.在这种情况下,你能帮帮我吗
Hi,
I am trying to write a SQL Server which assign a value to a temporary which is kept inside a if exists statement.
But is not working. Can you help me out in this case
declare @tempcomp int
if exists ((select @tempcomp=companysite_id from dbo.companysite_history(nolock) where companysite_id=1673301))
print @tempcomp
提前谢谢.
Govardhan
Thanks in advance.
Govardhan
推荐答案
declare @tempcomp int
SET @tempcomp= (select @tempcomp=companysite_id from dbo.companysite_history with(nolock) where companysite_id=1673301)
print @tempcomp
declare @tempcomp int
if exists (select companysite_id from dbo.companysite_history(nolock) where companysite_id=1673301)
select @tempcomp=companysite_id from dbo.companysite_history(nolock) where companysite_id=1673301
print @tempcomp
declare @tempcomp int
SET @tempcomp = -1 --Some default value
select @tempcomp=companysite_id from dbo.companysite_history(nolock) where companysite_id=1673301
IF @tempcomp <> -1
BEGIN
--Do something when the value is in the table
END
这篇关于如果在SQL Server中存在语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!