Home > Archive > ASE Database forum > October 2005 > T-SQL IF issues









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author T-SQL IF issues
dontspam.hws@willspc.net

2005-10-28, 7:23 am

I'm having an issue with some t-sql...

I'm trying to check for the existence of a table before
creation...

IF (select count(*) from sysobjects where name = "mytable" )
= 0
create table dbo.mytable (
my_field1 char(6) not null,
my_field2 char(50) not null,
valid int DEFAULT 1
)
ELSE
IF (select count(*) from sysobjects, syscolumns where
sysobjects.name="mytable" and sysobjects.id = syscolumns.id
and syscolumns.name="valid") = 0
alter table mytable add valid int default 1


When I try executing it, I get the following error:

Server Message: Number 2714, Severity 16
Line 2:
There is already an object named mytable' in the database

remove the dontspam {period} for email
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com