SQL Statment to convert boolean to true or false

I have a very basic understanding of sql queries. In VS 2010 I am running the following simple sql statment.

select distinct ivm_printedflag from Invoice

The field is boolean and I have no clue how to modiy my statment to convert it to where 1 = true and 0 = false. How would I accomplish this as I'm sure it's simple.
tmaususerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
In a SQL Server bit field (equivalent to Boolean) 1 = True and 0 = False.
If you meant the character values 'True' and False, then in SQL Server that's a CASE statement.

SELECT CASE ivm_printedflag WHEN 1 THEN 'True' WHEN 0 THEN 'False' END as make_up_a_name_here

Open in new window


bit fields can also contain a NULL value, so you might have to add a WHEN..THEN block above to handle those.

For an image and code-heavy tutorial on CASE blocks check out my article SQL Server CASE Solutions.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tmaususerAuthor Commented:
When I do that I get an invalid column name ivm_printed flag
Jim HornMicrosoft SQL Server Data DudeCommented:
>When I do that I get an invalid column name ivm_printed flag
Then the table/view 'invoice' does not have a column with that name, so check your spelling.  
Make sure the space before flag is correct, flag is not flg, ...
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

tmaususerAuthor Commented:
Sorry forgot the from invoice
tmaususerAuthor Commented:
Thanks, I'm sorry I missed one more thing in my original post. Where would I put "distinct" to differentiate between true or false? Does that make sense?
Jim HornMicrosoft SQL Server Data DudeCommented:
Lose the DISTINCT, that's a different deal, where you can eliminate duplicates in a set.

For example..
CREATE TABLE #tmp (id int) 

INSERT INTO #tmp (id) 
VALUES (1), (1), (2), (4), (42)

-- Duplicates
SELECT id FROM #tmp ORDER BY id

-- No Duplicates
SELECT DISTINCT id FROM #tmp ORDER BY id

Open in new window

tmaususerAuthor Commented:
Again, sorry if I am not clear. I want to eliminate duplicates. Basically I want the ability to choose true or false from a drop down using a reporting tool build into my erp system. The reporting tool is devexpress if that matters. I am looking for the select stament that can accomplish this which I would plug into my report writer in the list expression section.
Jim HornMicrosoft SQL Server Data DudeCommented:
>Again, sorry if I am not clear.
Just to set expectations, get into an entertainment mindset and read Top Ten Ways to Ask Better Questions, especially Number Three.   I'm more than happy to answer your questions, but it is a far better use of expert time to ask them upfront instead of in a steady stream of follow-up questions.

Thanks in advance.
Jim HornMicrosoft SQL Server Data DudeCommented:
>Basically I want the ability to choose true or false from a drop down
Something like...

SELECT 'True' as label, 1 as value, 1 as sort_order
UNION ALL
SELECT 'False', 0, 2
ORDER BY sort_order

Open in new window


Then have the drop-down only display the label, but pass the value.
tmaususerAuthor Commented:
Sorry but what am I selecting on? When I run your last statment that gives me a great visual but how do I work that in ivm_printed flag? Sorry but i am not expert and getting confused.
Jim HornMicrosoft SQL Server Data DudeCommented:
This is your question.  If you're confused, then I propose that you step back, gather your thoughts, and re-ask the question in a manner that meets all your needs.
tmaususerAuthor Commented:
I beleive I have what I am looking for. Thank you very much for hanging in there with me and my below novice skills!
Jim HornMicrosoft SQL Server Data DudeCommented:
Thanks for the grade.  Good luck with your project.  -Jim
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.