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 |
bholmstrom
Yak Posting Veteran
76 Posts |
Posted - 2013-03-18 : 12:45:57
|
Good afternoon,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:SELECT NCOSUSEif exists (select * from dbo.sysobjects where id = object_id(N'dbo.NCOS_Data') and OBJECTPROPERTY(id, N'IsUserTable') = 1)DROP TABLE dbo.NCOS_Data GO CREATE TABLE dbo.NCOS_Data ( NC_UniqueID int identity(1,1),NC_Lead_Number varchar (50) )GONow I get this error in 2008Msg 156, Level 15, State 1, Line 4Incorrect syntax near the keyword 'if'.Bryan Holmstrom |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-18 : 12:55:25
|
SELECT NCOSUSE is invalidis NCOS db name? if yes, it should beUSE NCOSGO.. ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
bholmstrom
Yak Posting Veteran
76 Posts |
Posted - 2013-03-18 : 13:03:38
|
Monday brains uggThanksBryan Holmstrom |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-03-18 : 13:07:49
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2013-03-18 : 13:16:55
|
You can also use the object_id function instead of exists:IF object_id('dbo.NCOS_Data', 'U') IS NOT NULLDROP TABLE dbo.NCOS_Data;GO |
|
|
|
|
|