SQL案例问题

SQL案例问题,sql,sql-server,tsql,Sql,Sql Server,Tsql,我不知道这是否可以做到,但我想我会问的 我要做的是有一个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 这可以做到吗?不在案例陈述中 如果您想执行这样的控制流操作

我不知道这是否可以做到,但我想我会问的

我要做的是有一个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

这可以做到吗?

不在案例陈述中

如果您想执行这样的控制流操作,请改用If。@dateofDeath变量可以是您声明和分配的T-sql变量,也可以是SELECT语句本身

IF @dateofDeath = 'yes' BEGIN
   do something
END ELSE BEGIN
   do something else
END

不在案例陈述中

如果您想执行这样的控制流操作,请改用If。@dateofDeath变量可以是您声明和分配的T-sql变量,也可以是SELECT语句本身

IF @dateofDeath = 'yes' BEGIN
   do something
END ELSE BEGIN
   do something else
END

你的意思是:如果另一张表中的某些内容是真的/存在的,那么就做一些事情

IF EXISTS (SELECT * FROM Client WHERE deathofdeath = yes)
   SELECT stuff FROM OtherTable

你的意思是:如果另一张表中的某些内容是真的/存在的,那么就做一些事情

IF EXISTS (SELECT * FROM Client WHERE deathofdeath = yes)
   SELECT stuff FROM OtherTable

就像保罗说的,你可以这样做:

select
    CASE
        WHEN client.deathofdeath = yes THEN (select top 1 therow from othertable where clientid=clientid.clientid)
        Else 0
    End AS DeathDate
From
    Client client

就像保罗说的,你可以这样做:

select
    CASE
        WHEN client.deathofdeath = yes THEN (select top 1 therow from othertable where clientid=clientid.clientid)
        Else 0
    End AS DeathDate
From
    Client client

我不确定你想在这里做什么?另一个选择是否打算返回仅在client.deathofdeath=yes或第二个结果集时才适用的其他列?仅当此处的另一个选择从另一个表返回标量值select COUNT*时,我不确定您在此处尝试执行什么操作?如果client.deathofdeath=yes或第二个结果集,则另一个select是否打算返回其他列?如果此处的另一个select从另一个表返回标量值select COUNT*