HOw to Set 'bit' variable to True Or False IN SQL Server SPROC/t-SQL

How do I initialize a field defined a 'bit' to 'True' or 'False'

I want to initialize a 'bit' field in an output table to True.

I tried the literal 'True'
I am now trying to set a bit variable to true and load that into the table field but that isn't working either.

I want to initialize a few fields way out to the right to be either true or false.  RIght now it is unsuccessfully using the variables @Truevar and @FalseVar.

HOw can initialize these fields on the output table to be true, or in some case false.

Perhaps it's really simple, like true = 1 and false = 0.  Just want to make sure.

Here's my code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- 
-- =============================================
ALTER PROCEDURE [dbo].[aConvertspProdNA_wInSPORC]
   
AS
BEGIN
    SET NOCOUNT ON;

	declare     @WkDate DATE
	declare     @wkUser  nvarChar(10)
	declare     @TrueVar    bit
	declare     @FalseVar   bit

	set @wkUser='Convert'
	set @wkdate = GETDATE()
--	set @TrueVar = True
--	'set @Falsevar  = False  
--
-- Clear the COmment Table
--
  Execute dbo.spDeleteAllRecsFromSQLTable 'tblProperty_Addresses'
--
--  Now load it
--
    INSERT INTO dbo.tblProperty_Addresses (  PropertyRecID,		Muni,		LotBlock,	TieBreaker,		JTSAddr1,		JTSAddr2,		JTSAddr3,		JTSAddr4,		JTSSeqNumber,		Name1,			Name2,			Address1,		City,		State,		ZipCode,   JTSOldControlNum,	BillingAddressYN,	  IncludeOnLegal ,   SequenceOnLegal,  UnMailable,		AddressCheckNeeded,		MailingAddress_YN ,  InterestTypeID ,   DefaultAddress_YN,  Active_YN ,   DateAdded,	UserAdded )
        SELECT								W.PropertyRecID, W.MuniCode,	W.LotBlock,	W.TieBreaker,	W.AddrLine1,	W.AddrLine2,	W.AddrLine3,	W.AddrLine4,	W.SequenceNumber,	W.AddrLine1,	W.AddrLine2,	W.AddrLine3,	W.City,		W.State,	W.Zip,		W.ControlNumber,	@Truevar,					@Falsevar,				0,				W.UnMailable,	W.AddressCheckNeeded,	@Truevar,				 4,					@Truevar,				@Truevar,			@wkDate,	@wkUser

        FROM dbo.bView_buildProd_NA W

END

Open in new window

LVL 1
mlcktmguyAsked:
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.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
bit variable only can store 0 or 1, it cannot store neither 'True' nor 'False'

try declare like this:

declare     @yourVar    bit

Open in new window


in your Insert statement, use:

case when @yourVar = 1 then 'True' else 'False' end

Open in new window


if you're refer to a table's field directly, use:

case when yourTable.yourField = 1 then 'True' else 'False' end

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
ste5anSenior DeveloperCommented:
And when you use SQL Server 2012+, you can use the IIF() function instead of the CASE..WHEN..END expression:

IIF(yourTable.yourField = 1, 'True', 'False')

Open in new window

0
mlcktmguyAuthor Commented:
Thanks
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
SQL

From novice to tech pro — start learning today.