Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Setting a value for a boolean
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  	@chvnNewDatabaseNam
e = 'NewDatabase'
 SET	@boolDatabaseExi
sts =
(
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


Report this thread to moderator Post Follow-up to this message
Old Post
KR
02-25-06 02:45 PM


Re: Setting a value for a boolean
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


Report this thread to moderator Post Follow-up to this message
Old Post
Razvan Socol
02-25-06 02:45 PM


Re: Setting a value for a boolean
Great!  Thanks so much!  They all work fine, and  I plan to use the
second option


Report this thread to moderator Post Follow-up to this message
Old Post
KR
02-25-06 02:45 PM


Re: Setting a value for a boolean
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.


Report this thread to moderator Post Follow-up to this message
Old Post
figital
02-25-06 02:45 PM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 04:48 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006