How do I return a boolean value from a query during condition evaluation?

前端 未结 4 1499
一向
一向 2021-01-02 06:14

I need something like this:

select (len(someLongTextColumn)=0) as isEmpty;

The above doesn\'t work,

any alternatives?

4条回答
  •  暖寄归人
    2021-01-02 06:51

    If you cast to bit, then most client code can read it as boolean directly (SQL Server doesn't have a boolean type)

    SELECT
        CAST(
            CASE
               WHEN len(someLongTextColumn) = 0 THEN 1 ELSE 0
            END AS bit
            ) as isEmpty;
    

    if you have many in one go, use bit variables like this: Imply bit with constant 1 or 0 in SQL Server

提交回复
热议问题