我不知道这是不是可以做到,但我想我会问一下。
我想要做的是有一个case语句查询,如果是1,则开始另一个操作。如果0什么也不做。
例如
select CASE WHEN client.deathofdeath = yes THEN 1
do another select in here (which is another table)
Else 0 End AS DeathDate
From Client client这可以做到吗?
发布于 2010-03-28 19:19:34
而不是在CASE语句中。
如果您想执行这样的控制流操作,请改用If。@dateofDeath变量可以是声明并赋值的T-sql变量,也可以是SELECT语句本身。
IF @dateofDeath = 'yes' BEGIN
do something
END ELSE BEGIN
do something else
END发布于 2010-03-28 20:01:01
你的意思是:如果某些东西是真的/存在于另一个表中,就做一些事情?
IF EXISTS (SELECT * FROM Client WHERE deathofdeath = yes)
SELECT stuff FROM OtherTable发布于 2010-03-30 10:17:33
就像unclepaul84说的,你可以这样做:
select
CASE
WHEN client.deathofdeath = yes THEN (select top 1 therow from othertable where clientid=clientid.clientid)
Else 0
End AS DeathDate
From
Client clienthttps://stackoverflow.com/questions/2532678
复制相似问题