C# 如何在sql中将位数据类型转换为varchar

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17220642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:52:54  来源:igfitidea点击:

how to convert bit datatype to varchar in sql

c#mysql

提问by user2327795

How to convert BIT datatype to Varchar in sql ?

如何在 sql 中将 BIT 数据类型转换为 Varchar?

I tried CAST

我试过 CAST

CAST(IsDeleted as Varchar(512))

CAST(IsDeleted as Varchar(512))

But it didn't work....

但它没有用......

Note: IsDeletedis a BIT datatype and I need to convert it into Varchar or Int

注意:IsDeleted是 BIT 数据类型,我需要将其转换为 Varchar 或 Int

采纳答案by Ed Gibbs

Assuming this is MySQL, you can't cast to VARCHAR. The allowable types are shown here; they're listed after the CONVERTfunction explanation.

假设这是 MySQL,您不能强制转换为VARCHAR. 此处显示允许的类型;它们列在CONVERT功能说明之后。

You can cast to CHAR(1)though. For example:

你可以投射到CHAR(1)。例如:

CAST(b'11' AS CHAR(1))

回答by David Scott

CAST(IsDeleted AS INT) AS IsDeleted

This should work I just tried it in SSMS and it works like a charm

这应该可以工作,我刚刚在 SSMS 中尝试过,它的作用就像一个魅力

回答by user2407394

SELECT
    CASE WHEN IsDeleted = 1 THEN 'True' ELSE 'False' END AS IsDel
FROM
    Table

回答by Keith

is the attribute nullable?

是属性nullable

Try

尝试

CONVERT(varchar, ISNULL(isDeleted,0))