473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Setting a value for a boolean

KR
Hi,

I am trying to get a 0 or 1 depending on the sucess or failure of a
t-sql statement, and here is what I have:

Declare @boolDatabaseExists bit
Declare @chvnNewDatabaseName nvarchar(260)

SET @chvnNewDatabaseName = 'NewDatabase'
SET @boolDatabaseExists =
(
SELECT (1)
FROM master.dbo.sysdatabases
WHERE name = @chvnNewDatabaseName

)

Print @boolDatabaseExists

What it is doing right now is that it prints a 1 for when there is a
match for the @NewDatabaseName in the sysdatabases table. If there is
not a match, then there is no value set for @ boolDatabaseExists
What I would like it to do is if there is no match for the
@NewDatabaseName in the sysdatabases, I would like to set the
boolDatabaseExists to 0

I hope I am clear in my explanation.

Thank you

KR

Feb 22 '06 #1
3 15178
Hello, KR

You can use one of the following:

IF EXISTS (
SELECT *
FROM master.dbo.sysdatabases
WHERE name = @chvnNewDatabaseName
)
SET @boolDatabaseExists = 1
ELSE
SET @boolDatabaseExists = 0

or:

SET @boolDatabaseExists = CASE
WHEN EXISTS (
SELECT *
FROM master.dbo.sysdatabases
WHERE name = @chvnNewDatabaseName
) THEN 1 ELSE 0 END

or:

SET @boolDatabaseExists = (
SELECT COUNT(*)
FROM master.dbo.sysdatabases
WHERE name = @chvnNewDatabaseName
)

Razvan

Feb 22 '06 #2
KR
Great! Thanks so much! They all work fine, and I plan to use the
second option

Feb 22 '06 #3
You could probably just initialize the bit to 0, too. That way if there
is no result, it is still equal to 0/false. The options provided by
Razvan are good, though.

Feb 23 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Rob | last post by:
I have a public class setup as follows Public Class Variables Shared Property FranFormOpen() As Boolean Get Return FranFormOpen End Get Set(ByVal Value As Boolean) FranFormOpen = Value
4
by: thomastk | last post by:
Hi, In the following script, I am trying to set selection to a select option element, that is newly created within the script. It works fine on IE installations on Windows 2000 and some XP...
5
by: Mark | last post by:
Hi All, This maybe a really simple question but I need some help. I have been having problems with security and thanks to the help received from a reply to an earlier post, I have found a...
10
by: MLH | last post by:
I have an A97 table with a Yes/No field named TowJob and a form bound to that table. The TowJob control on the form is bound to the same field. It is an option group with Yes and No bttns valued...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
0
by: Nate Hekman | last post by:
I'm trying to set up a Membership/Role Provider for an ASP.NET 2.0 beta 2 site using SqlMembershipProvider, and am having problems configuring SQL Server. I'm comfortable with ASP.NET but very...
4
by: Brian Mitchell | last post by:
Is there an easy way to flip the value of a boolean variable without first seeing what it's set to?
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: PetterL | last post by:
I have a setting called My.settings.firstrun set to True, set in the setting manager. When i read this in the first form form_Load in a IF sentence it always come out as false. I have tried to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.