I am trying to convert a boolean to an integer. Here is the coding I have so far:
CONVERT(int, column_name) AS ALIAS
The query runs without an error. However, it is not producing the results I want.
What do I need to do?
What you are doing should be enough to convert BIT values to int as shown below.
DECLARE @TABLE TABLE(Value BIT)
INSERT INTO @TABLE VALUES
(1),(0),(1),(0),(1),(0),(1)
Query
SELECT Value
,CAST(Value AS INT) AS Casted
,CONVERT(int, Value) AS Converted
FROM @TABLE
Result Set
╔═══════╦════════╦═══════════╗
║ Value ║ Casted ║ Converted ║
╠═══════╬════════╬═══════════╣
║ 1 ║ 1 ║ 1 ║
║ 0 ║ 0 ║ 0 ║
║ 1 ║ 1 ║ 1 ║
║ 0 ║ 0 ║ 0 ║
║ 1 ║ 1 ║ 1 ║
║ 0 ║ 0 ║ 0 ║
║ 1 ║ 1 ║ 1 ║
╚═══════╩════════╩═══════════╝
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With