Cast from varchar to bit

I'm receiving an error: Conversion failed when converting the varchar value 'Yes' to data type int.

I'm using the code:
INSERT INTO ...
CASE WHEN @IsAllDay = 'Yes' THEN CAST(1 AS BIT) ELSE CAST(0 AS BIT) END

How do use CASE to convert Yes to a Bit value of 1?

I've tried:
CASE WHEN @IsAllDay = 'Yes' THEN True ELSE False END
barnescoAsked:
Who is Participating?
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.

tim_csCommented:
Can we see all of the script/proc?
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Copy-paste this into your SSMS, execute it to verify it works, and modify it to meet your needs.
Declare @val char(3) = 'Yes'

CREATE TABLE #tmp (value bit) 

INSERT INTO #tmp (value)
SELECT CASE @val WHEN 'Yes' THEN 1 WHEN 'No' THEN 0 END

SELECT * FROM #tmp

Open in new window

0

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
Shaun KlineLead Software EngineerCommented:
Is the @IsAllDay a varchar or is it an integer data type?
0
barnescoAuthor Commented:
That worked...turned out my problem was in another part of the query, but at least this ruled out any incorrect syntax. I appreciate the help.
0
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
Microsoft SQL Server

From novice to tech pro — start learning today.