Hello to you all.
I'm trying to execute in Query Analyzer this script i have written
Use dokimastiki
go
Begin
Declare @stbname nvarchar(256)
Declare @smessage varchar(20)
DECLARE PKMS_Tables CURSOR FOR
select name from sysobjects
Where xtype = 'U'
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @stbname
WHILE @@FETCH_STATUS = 0
BEGIN
Case LTRIM(@stbname)
when 'replicas' then print @stbname
When 'replicas_codes_locations' then print @stbname
when 'replicas_locations' then print @stbname
when 'counters' then print @stbname
when 'danaos_supply_setting' then print @stbname
when 'dtproperties' then print @stbname
when 'tabledeleteno' then print @stbname
ELSE
BEGIN
Truncate Table LTRIM(@stbname)
END
END
FETCH NEXT FROM PKMS_Tables INTO @stbname
END
END
CLOSE PKMS_Tables
Deallocate PKMS_TAbles
Go
The case statement is for not to delete the specific tables
but truncate all the rests.The query when it is executed in Query analyzer shows me the following errors
Incorrect Syntax near the keyword 'Case'
line 24 : Incorrect syntax near '@stbname'
incorrect syntax near the keyword 'END'
All i'm trying to do is from a schema truncate all the tables except the table names that i have putted hardcoded inside my script.
Can anyone help me with this??
zkar programmer
I'm trying to execute in Query Analyzer this script i have written
Use dokimastiki
go
Begin
Declare @stbname nvarchar(256)
Declare @smessage varchar(20)
DECLARE PKMS_Tables CURSOR FOR
select name from sysobjects
Where xtype = 'U'
OPEN PKMS_Tables
FETCH NEXT FROM PKMS_Tables INTO @stbname
WHILE @@FETCH_STATUS = 0
BEGIN
Case LTRIM(@stbname)
when 'replicas' then print @stbname
When 'replicas_codes_locations' then print @stbname
when 'replicas_locations' then print @stbname
when 'counters' then print @stbname
when 'danaos_supply_setting' then print @stbname
when 'dtproperties' then print @stbname
when 'tabledeleteno' then print @stbname
ELSE
BEGIN
Truncate Table LTRIM(@stbname)
END
END
FETCH NEXT FROM PKMS_Tables INTO @stbname
END
END
CLOSE PKMS_Tables
Deallocate PKMS_TAbles
Go
The case statement is for not to delete the specific tables
but truncate all the rests.The query when it is executed in Query analyzer shows me the following errors
Incorrect Syntax near the keyword 'Case'
line 24 : Incorrect syntax near '@stbname'
incorrect syntax near the keyword 'END'
All i'm trying to do is from a schema truncate all the tables except the table names that i have putted hardcoded inside my script.
Can anyone help me with this??
zkar programmer