SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How To? -- DTS, Excel, Send Mail Task


How To? -- DTS, Excel, Send Mail Task

Author
Message
jsblakley
jsblakley
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 1

Not sure where to post my question, so I applolgize if this is in the wrong forum.

I have a DTS job that runs a sql query to join 3 tables to pull data needed for an excel spreadsheet and then on completion, the excel spreadsheet is emailed to a user.

My problem is that this runs multiple times a day and currently, the excel spreadsheet is just appended to. I need it to NOT append but to create a new excel spreadsheet. If I manually remove the excel spreadsheet, then DTS fails indicating that a temp table(created by DTS for the excel spreadsheet) does not exist.

How do I create the spreadsheet from scratch each time the DTS is executed?

Jeff





fromnaija
fromnaija
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1120 Visits: 61
There are more than one way to skin a cat. One solution in this case is to use ActiveX, open the Excel spreadsheet and remove all the data at the beginning of the DTS.


Joseph

jerry.mccarthy@ie.flextronics....
jerry.mccarthy@ie.flextronics.com
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 2
Create your Excel workbook, format as required, then delete any data rows in it, then store a copy somewhere the DTS can access. Have an ActiveX delete the existing workbook, copy the new empty workbook to the same location then run the DTS task to transfer your data to the new empty workbook. Data goes in and adopts all the formatting applied to the original data...



wildh
wildh
SSC-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 Visits: 675
I skin my cat this way - I create a sql task who's connection is the spreadsheet and drop the table and recreate it. eg. drop table err_screwup go create table 'err_screwup' ('user' varchar(30), 'err' decimal (28,8)). Works a treat.



ChrisMoix
ChrisMoix
Old Hand
Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)Old Hand (364 reputation)

Group: General Forum Members
Points: 364 Visits: 1
Could you give me some more detail on how you do this, wildh? I am currently doing the ActiveX script to copy an empty template over the end excel file, but if I could simplify the process, I would certainly like to!



wildh
wildh
SSC-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 Visits: 675
In excel
Create a spreadsheet called screwup.xls

In MMC
Create a SQL server connection
Create a spreadsheet connection (who’s filename is the screwup.xls file)
Create the Transform data task, in the source type “select 'user1' as [username], '1000' as err” in the SQL query. In destination click “create and change table name to “screwup”. Note. copy out the statement you will need it later it may look like CREATE TABLE `screwup` (`username` VarChar (5) , `err` VarChar (4) )

Execute the Transform data task twice and open the spreadsheet. You will see two records.

Create a SQL task who’s existing connection is the excel spreadsheet. Remember, the sheet “screwup” is treated like a table so you must drop it and re- create it, so type in “drop table screwup go” and now paste your create table syntax. Truncate table won’t work.
Create an on completion/ success precedence from the SQL task to the SQL server connection.

Run the package again and open the spreadsheet, there should be only one record.

Hope this is the kind of thing you’re looking for and that my guide is straightforward.



jsblakley
jsblakley
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 1
That works like a charm! Simple and straight-forward. Thanks for the help.



Terri-92562
Terri-92562
SSC Veteran
SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)

Group: General Forum Members
Points: 294 Visits: 1242

Create a SQL task who’s existing connection is the excel spreadsheet. Remember, the sheet “screwup” is treated like a table so you must drop it and re- create it, so type in “drop table screwup go” and now paste your create table syntax

I tried the above suggestion of wildh and get an error on the drop table:

"Cannot drop table 'Screwup', because it does not exist in the system catalog"

The Excel file was created with the 2 records as described. What am I missing?

Terri

tsanta@lsuhsc.edu





Terri

To speak algebraically, Mr. M. is execrable, but Mr. C. is
(x+1)-ecrable.
Edgar Allan Poe
[Discussing fellow writers Cornelius Mathews and William Ellery Channing.]
Terri-92562
Terri-92562
SSC Veteran
SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)SSC Veteran (294 reputation)

Group: General Forum Members
Points: 294 Visits: 1242

Never mind, the SQL task had the wrong connection. It works now, if the Excel file exists. Is there a way to check if the file exists before dropping it? I tried : IF NOT (OBJECT_ID('Screwup') IS NULL) DROP TABLE Screwup

but I get an error. Where can I find the syntax I can use here?





Terri

To speak algebraically, Mr. M. is execrable, but Mr. C. is
(x+1)-ecrable.
Edgar Allan Poe
[Discussing fellow writers Cornelius Mathews and William Ellery Channing.]
wildh
wildh
SSC-Addicted
SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)SSC-Addicted (418 reputation)

Group: General Forum Members
Points: 418 Visits: 675
tsanta, sorry for any delay!! have a browse and replace the print statement with other syntax.

http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=114315#bm116592

Hop it points you in the right direction.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search