Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Mithun
Starting Member
1 Post |
Posted - 2010-03-05 : 22:34:57
|
| Hi All,I have a Job which executes the below query to check the availability of a tableIF ( NULL != OBJECT_ID( 'table_mit' ) )BEGIN PRINT '' PRINT ' ... Dropping table: table_mit' PRINT '' DROP TABLE table_mitENDGOPRINT ''PRINT ' Create table: table_mit'PRINT ''GOCREATE TABLE table_mit ( Name Char(10) NOT NULL ,First Name Char(10) NOT NULL ,Last Name Char(30) NOT NULL)GOthe table table_mit already exist in my database but the conditionIF ( NULL != OBJECT_ID( 'table_mit' ) ) is failing Can somebody help me out why is this happening |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2010-03-05 : 23:46:13
|
| try like thisIF ( OBJECT_ID('table_mit') IS NOT NULL )BEGINPRINT ''PRINT ' ... Dropping table: table_mit'PRINT ''DROP TABLE table_mitENDGO |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-06 : 02:09:19
|
quote: Originally posted by Mithun Hi All,I have a Job which executes the below query to check the availability of a tableIF ( NULL != OBJECT_ID( 'table_mit' ) )BEGIN PRINT '' PRINT ' ... Dropping table: table_mit' PRINT '' DROP TABLE table_mitENDGOPRINT ''PRINT ' Create table: table_mit'PRINT ''GOCREATE TABLE table_mit ( Name Char(10) NOT NULL ,First Name Char(10) NOT NULL ,Last Name Char(30) NOT NULL)GOthe table table_mit already exist in my database but the conditionIF ( NULL != OBJECT_ID( 'table_mit' ) ) is failing Can somebody help me out why is this happening
You cant use operators like = ,!= etc to compare with NULL unless you've ANSI NULL settings off which is not the default. Under default conditions NULL is not regarded as a value but it represents condition unknown or undefined value. So you need to use IS NULL or IS NOT NULL for comparisons of null values------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|