×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Drop/Truncate tables based on a stored procedures value

Drop/Truncate tables based on a stored procedures value

Drop/Truncate tables based on a stored procedures value

(OP)
I have the following so far -
USE MASTER
CREATE TABLE #TEMP_PHARM (
FILE_EXISTS INT
,FILE_DIRECTORY INT
,PARENT_DIRECTORY INT
)

INSERT INTO #TEMP_PHARM
EXEC xp_fileexist 'file path \ filename'

SELECT * FROM #TEMP_PHARM

Now I want to start DROP OR TRUNCATING tables (from a different database then the MASTER) where the value of FILE_EXISTS = 1 from the #TEMP_PHARM table

Any and all help is appreciated!!!

RE: Drop/Truncate tables based on a stored procedures value

So, your code will create a table (with some sample data, I guess here):

#TEMP_PHARM
FILE_EXISTS  FILE_DIRECTORY  PARENT_DIRECTORY
   1           234               123
   1           456               876
   0           654               667 

What tables do you want to DROP or TRUNCATE based on the data in #TEMP_PHARM table?

Or am I getting this picture wrong ponder

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Drop/Truncate tables based on a stored procedures value

(OP)
Hi Andy,

I want to drop/truncate tables in a different database
i.e. - DROP TABLE [database].[schema].RDTFOO

RE: Drop/Truncate tables based on a stored procedures value

How do you know which tables to DROP?
It doesn't look (to me) your #TEMP_PHARM table holds any table names....

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Drop/Truncate tables based on a stored procedures value

(OP)
It's part of an overall SQL query.
If the file is present -
1. drop tables
2. update table with new file
3. Do some table/field cleanup

RE: Drop/Truncate tables based on a stored procedures value

I see we will not communicate since you refuse to answer any of my questions. Too bad. sad

But, as a side note: CREATE TABLE ‘on-the-fly’, DROP TABLE ‘on-the-fly’, TRUNCATE TABLE ‘on-the-fly’ is possible, but why? That’s not the ‘regular’ approach to deal with the data in the DB (as far as I know). Why not just create a ‘permanent’ table once, set the fields needed, and then INSERT (instead of CREATE) records when needed, and UPDATE and/or DELETE records (instead of DROP or TRUNCATE temp tables) when needed.

There are uses/needs for temp tables in the DB, but for 99% of cases there are better solutions in well designed, normalized, relational data base.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson

RE: Drop/Truncate tables based on a stored procedures value

(OP)
How do I reply directly to Andy?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close