Re: Testing Table Existence - DB name as variable ?
From: Roji. P. Thomas (lazydragon_at_nowhere.com)
Date: 06/27/04
- Next message: Joe Celko: "Re: Hypothetical speed increase with parent/child records"
- Previous message: Roji. P. Thomas: "Re: Date Functions..."
- In reply to: rob: "Testing Table Existence - DB name as variable ?"
- Next in thread: rob: "Re: Testing Table Existence - DB name as variable ?"
- Reply: rob: "Re: Testing Table Existence - DB name as variable ?"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 27 Jun 2004 20:11:02 +0530
Oh Rob,
You are trying to mix dynamic SQL and Static SQL.
You cannot do that. Your Else condition doesnt have a
corresponding IF condition. thats why you are getting the error.
To learn more abt dynamic SQL read
http://www.sommarskog.se/dynamic_sql.html
-- Roji. P. Thomas SQL Server Programmer "rob" <rwc1960@bellsouth.net> wrote in message news:PKzDc.129$O3.27@bignews2.bellsouth.net... > I am doing something wrong in the code below... > > This section fails within the cursor... I am attempting to check for > existence of a table in the database names I am looping through... > > As is, Error is Incorrect syntax near keyword 'ELSE' > If I comment out from BEGIN to the END, Error is Incorrect syntax near ')' > > Thanks ! > > DECLARE @sql as varchar(8000) > DECLARE @SalespersonDB as varchar(8000) > > set @SalespersonDB = 'EJ' > set @sql = ' if exists (select * from dbo.sysobjects where id = object_id([' > + @SalespersonDB + '].[dbo].[tblCustPrClChanlSlsREP]))' > print @sql > Exec(@sql) > BEGIN > Print 'Do nothing' > END > ELSE > BEGIN > Print 'Do something' > End > >
- Next message: Joe Celko: "Re: Hypothetical speed increase with parent/child records"
- Previous message: Roji. P. Thomas: "Re: Date Functions..."
- In reply to: rob: "Testing Table Existence - DB name as variable ?"
- Next in thread: rob: "Re: Testing Table Existence - DB name as variable ?"
- Reply: rob: "Re: Testing Table Existence - DB name as variable ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|