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 |
|
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_V1How would I drop this table if they dates in the name change daily?i.e. POLICY_NCCI_20080708_SUBMISSION_20080710_V1I'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 |
 |
|
|
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_V1but the next day the job is rerun and the table will have the namePOLICY_NCCI_20080708_SUBMISSION_20080710_V1I 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.htmlDECLARE @tbl sysnameDECLARE drop_tbl_cur INSENSITIVE CURSOR FORSELECT name FROM sysobjects WHERE name like '%[0-9]'OPEN CURSOR drop_tbl_curWHILE 1 = 1BEGINFETCH drop_tbl_cur INTO @tblIF @@fetch_status <> 0BREAKEXEC ('DROP TABLE ' + @tbl)ENDDEALLOCATE drop_tbl_cur |
 |
|
|
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? |
 |
|
|
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.. |
 |
|
|
|
|
|