March 18th, 2013, 11:48 AM
SQL 2008 vs 2005 New Error on "If"
I have a query that generates a table and its fields that works in 2005. Now I am on a 2008 Server and the query no longer works.
Was working code:
if exists (select * from dbo.sysobjects where id = object_id(N'dbo.NCOS_Data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE dbo.NCOS_Data
CREATE TABLE dbo.NCOS_Data (
NC_UniqueID int identity(1,1),
NC_Lead_Number varchar (50)
Now I get this error in 2008
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'if'.
You are missing the database name in your statement.
if exists (select * from
You need to insert your table name for this to work. Change ??? to your table name.
it should be
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NCOS_Data]') AND type in (N'U'))
DROP TABLE [dbo].[NCOS_Data]