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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Drop Table

Author  Topic 

madscientist
Starting Member

30 Posts

Posted - 2008-07-09 : 17:29:22
Hello everyone,

I generate a table and in the name of the table there are appended dates.

i.e. POLICY_NCCI_20080708_SUBMISSION_20080709_V1

How would I drop this table if they dates in the name change daily?

i.e. POLICY_NCCI_20080708_SUBMISSION_20080710_V1

I'm thinking about using "Like" but don't know how to add that in.

Thank you very much in advance.

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-07-09 : 18:35:55

Drop table yourtablename_date
Go to Top of Page

madscientist
Starting Member

30 Posts

Posted - 2008-07-09 : 19:30:20
Thank you sodeep but its not what im looking for. See the table name can be:

POLICY_NCCI_20080708_SUBMISSION_20080709_V1

but the next day the job is rerun and the table will have the name

POLICY_NCCI_20080708_SUBMISSION_20080710_V1

I want to use something like drop table where LIKE "POLICY_NCCI_" as that will always remain the same.

Here is a link that talks about something like it but I dont understand throughly the coding behind it.

http://bytes.com/forum/thread82727.html

DECLARE @tbl sysname
DECLARE drop_tbl_cur INSENSITIVE CURSOR FOR
SELECT name FROM sysobjects WHERE name like '%[0-9]'
OPEN CURSOR drop_tbl_cur
WHILE 1 = 1
BEGIN
FETCH drop_tbl_cur INTO @tbl
IF @@fetch_status <> 0
BREAK
EXEC ('DROP TABLE ' + @tbl)
END
DEALLOCATE drop_tbl_cur
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-10 : 01:12:34
What are date values that are appended to table names?
Go to Top of Page

ssnaik84
Starting Member

15 Posts

Posted - 2008-07-10 : 03:20:38
SELECT [name] FROM sysobjects where xtype='U' AND name like 'POLICY_NCCI_%_SUBMISSION_%_V1'

try by using this query in your cursor..
Go to Top of Page
   

- Advertisement -