Showing posts with label task. Show all posts
Showing posts with label task. Show all posts

Sunday, March 25, 2012

Change Email Task Properties

HI,

How can I programmatically change the properties of Send Mail task using Script Task. I want to change the From, To and Attachment parameters of the Send Mail task.

If the Script Task can't do it, Is there any alternative to do?

Thanks

All those questions are answered here: http://blogs.conchango.com/jamiethomson/archive/2006/06/28/4156.aspx

-Jamie

Wednesday, March 7, 2012

challenging search task is not working as expected

Hi Guys,

I have two tables called table1 and table2.

table1 has search words and table2 has file names as below and want to get file names from table2 those match with all search words.

table1

-

-searchword- column name

--

Learn more about melons row0

--

%.txt row1

-

table2

-testname- column name

--

FKOV43C6.EXE

-
frusdr.txt

-
FRUSDR.TXT


SPGP_FWPkg_66G.zip


readme.txt

--
README.TXT

-
watermelon.exe

-
Learn more about melons read me.txt

-

Here is the script what I have tried...............I hope some one will help to come out this loop.Thanks in advance.

===============================================================================

select * from @.table2 t2 where t2.[testname] in (

SELECT tb.[testname] FROM @.table1 ta

JOIN @.table2 tb ON '% ' + tb.[testname] + ' %' LIKE '% ' + ta.searchword + ' %'

group by tb.[testname] having count(*) = (SELECT COUNT(*) FROM @.table1)

)

===============================================================================

script to create tables

============================================================================

DECLARE @.table1 TABLE (

searchword VARCHAR(255)

)

INSERT INTO @.table1 (

searchword

) VALUES ( 'Learn more about melons' )

INSERT INTO @.table1 (

searchword

) VALUES ( '%.txt' )

DECLARE @.table2 TABLE (

testname VARCHAR(255)

)

INSERT INTO @.table2 (

testname

) VALUES ( 'FKOV43C6.EXE' )

INSERT INTO @.table2 (

testname

) VALUES ('frusdr.txt' )

INSERT INTO @.table2 (

testname

) VALUES ('FRUSDR.TXT' )

INSERT INTO @.table2 ( testname

) VALUES ( 'SPGP_FWPkg_66G.zip' )

INSERT INTO @.table2 (

testname

) VALUES ( 'readme.txt' )

INSERT INTO @.table2 (testname

) VALUES ('README.TXT' )

INSERT INTO @.table2 (testname) VALUES (

'watermelon.exe' )

INSERT INTO @.table2 (

testname

) VALUES ('Learn more about melons read me.txt' )

SELECT * FROM @.table2

DECLARE @.table3 TABLE (

testname VARCHAR(255)

)

INSERT INTO @.table2 (

testname

) VALUES ('Melon release NOTES 321.xls' )

===================================================================================

Here it is:

DECLARE @.num AS int;
SELECT @.num = COUNT(*) FROM @.table1;

SELECT tb.[testname] FROM @.table1 ta
cross JOIN (select distinct * from @.table2) tb
where tb.[testname] LIKE + '%' + ta.searchword + '%'
group by tb.[testname] having count(ta.searchword) = @.num
|||

maybe you also should take an look on "full text index":

f. ex. contains-function

|||

Hi Zuomin,

Thank you very much.It worked perfectly. Thanks for spending your valuable time.

challenging search task is not working as expected

Hi Guys,

I have two tables called table1 and table2.

table1 has search words and table2 has file names as below and want to get file names from table2 those match with all search words.

table1

-

-searchword- column name

--

Learn more about melons row0

--

%.txt row1

-

table2

-testname- column name

--

FKOV43C6.EXE

-
frusdr.txt

-
FRUSDR.TXT


SPGP_FWPkg_66G.zip


readme.txt

--
README.TXT

-
watermelon.exe

-
Learn more about melons read me.txt

-

Here is the script what I have tried...............I hope some one will help to come out this loop.Thanks in advance.

===============================================================================

select * from @.table2 t2 where t2.[testname] in (

SELECT tb.[testname] FROM @.table1 ta

JOIN @.table2 tb ON '% ' + tb.[testname] + ' %' LIKE '% ' + ta.searchword + ' %'

group by tb.[testname] having count(*) = (SELECT COUNT(*) FROM @.table1)

)

===============================================================================

script to create tables

============================================================================

DECLARE @.table1 TABLE (

searchword VARCHAR(255)

)

INSERT INTO @.table1 (

searchword

) VALUES ( 'Learn more about melons' )

INSERT INTO @.table1 (

searchword

) VALUES ( '%.txt' )

DECLARE @.table2 TABLE (

testname VARCHAR(255)

)

INSERT INTO @.table2 (

testname

) VALUES ( 'FKOV43C6.EXE' )

INSERT INTO @.table2 (

testname

) VALUES ('frusdr.txt' )

INSERT INTO @.table2 (

testname

) VALUES ('FRUSDR.TXT' )

INSERT INTO @.table2 ( testname

) VALUES ( 'SPGP_FWPkg_66G.zip' )

INSERT INTO @.table2 (

testname

) VALUES ( 'readme.txt' )

INSERT INTO @.table2 (testname

) VALUES ('README.TXT' )

INSERT INTO @.table2 (testname) VALUES (

'watermelon.exe' )

INSERT INTO @.table2 (

testname

) VALUES ('Learn more about melons read me.txt' )

SELECT * FROM @.table2

DECLARE @.table3 TABLE (

testname VARCHAR(255)

)

INSERT INTO @.table2 (

testname

) VALUES ('Melon release NOTES 321.xls' )

===================================================================================

Here it is:

DECLARE @.num AS int;
SELECT @.num = COUNT(*) FROM @.table1;

SELECT tb.[testname] FROM @.table1 ta
cross JOIN (select distinct * from @.table2) tb
where tb.[testname] LIKE + '%' + ta.searchword + '%'
group by tb.[testname] having count(ta.searchword) = @.num
|||

maybe you also should take an look on "full text index":

f. ex. contains-function

|||

Hi Zuomin,

Thank you very much.It worked perfectly. Thanks for spending your valuable time.

Challanging task, for fun - answer two questions from given data!

Hi, I'm looking for the answer to these questions.
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
ONLY by reading information given. No DB's is needed!
Following table contain info about persons. Table do contain a lot of
rows!
CREATE TABLE Person
{
PersonID int NOT NULL IDENTITY(1,1)
PersNumber char(11) NOT NULL,
Name1 varchar(50) NOT NULL,
Name2 varchar(50) NOT NULL,
ShoeSize int NOT NULL,
Address varchar(50) NOT NULL,
Zip varchar(10) NOT NULL,
City varchar(50) NOT NULL
}
Further more, this table containg cars connected to persons in table
above.
CREATE TABLE Car
{
CarID int NOT NULL IDENTITY(1,1),
RegNr varchar(8) NOT NULL,
PersonID int NULL
}
Following SELECT statements are executed:
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 1
(132892 rows are affected)
SELECT PersNumber, COUNT(*)
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
GROUP BY PersNumber
HAVING COUNT(*) > 2
(0 rows are affected)
SELECT COUNT(DISTINCT P. PersonID), COUNT (DISTINCT C.CarID)
FROM Person P FULL OUTER JOIN Car C ON P.PersonID = C.PersonID
WHERE C.CarID IS NULL OR P.PersonID IS NULL
-- --
198898 114388
(1 rows are affected)
Now...the answers.. GOOD LUCK!!! :)
1. How many rows contained in table PERSON
2. How many rows contained in teble CAR
Thanks to all gurus taking time solving this. Please, if you know this
- try to explain your solution!
Thanks again!!
/Markthere are 1037854 cars belonging to a person
SELECT *
FROM Person P JOIN Car C ON P.PersonID = C.PersonID
(1037854 rows is affected)
and 114388 cars not belonging to anyone
total cars 1037854 + 114388
Similarly, there are (1037854 - 132892 - 0) persons having cars, and
198898 persons without cars
HIH

Thursday, February 16, 2012

Catching errors in SSIS Backup Database Task

Hi,

In my SSIS package, I have a backup database task. When I run the package with DestinationAutoFolderPath set to a folder ("Network Service" account has full permission on this folder) and DestinationCreationType set to Auto, the task works just fine creating a backup with its own name. (similar to database_date<count>).

But what I want is in my front-end I am allowing the user to specify the name of the backup file. So I want the task to create the backup file in the name I supply. I set the DestinationCreationType to manual and in the application code added the DestinationManualList with the path from the UI.

Now the pacakge runs fine but does not take any backup. There is no errors as well. If I set the FailPackageOnFailure and FailParentOnFailure to true, then I am getting the DTSExecResult.Failure but I am not getting the actual error from the backup database task.

Am I missing anything here?

Thanks in advance,
Srikanth.

How are you executing the package?

What does the logfile (I assume that you have one) say?

-Jamie

|||

Thanks a lot for the reply.

I enabled the log in package and the backup database task. The following is the text appears in the log file:

#Fields: event,computer,operator,source,sourceid,executionid,starttime,endtime,datacode,databytes,message
OnPreValidate,SERVER211,SERVER211\Administrator,DICoreDataPackage,{8B470140-EB79-4A15-A2A7-10590065310C},{844D2D28-16D8-42C8-9E1F-3E1506544BE5},8/29/2006 11:31:28 AM,8/29/2006 11:31:28 AM,0,0x,(null)
PackageStart,SERVER211,SERVER211\Administrator,DICoreDataPackage,{8B470140-EB79-4A15-A2A7-10590065310C},{844D2D28-16D8-42C8-9E1F-3E1506544BE5},8/29/2006 11:31:28 AM,8/29/2006 11:31:28 AM,0,0x,Beginning of package execution.

Diagnostic,SERVER211,SERVER211\Administrator,DICoreDataPackage,{8B470140-EB79-4A15-A2A7-10590065310C},{844D2D28-16D8-42C8-9E1F-3E1506544BE5},8/29/2006 11:31:28 AM,8/29/2006 11:31:28 AM,0,0x,Based on the system configuration, the maximum concurrent executables are set to 3.

OnPreExecute,SERVER211,SERVER211\Administrator,DICoreDataPackage,{8B470140-EB79-4A15-A2A7-10590065310C},{844D2D28-16D8-42C8-9E1F-3E1506544BE5},8/29/2006 11:31:28 AM,8/29/2006 11:31:28 AM,0,0x,(null)
PackageEnd,SERVER211,SERVER211\Administrator,DICoreDataPackage,{8B470140-EB79-4A15-A2A7-10590065310C},{844D2D28-16D8-42C8-9E1F-3E1506544BE5},8/29/2006 11:31:29 AM,8/29/2006 11:31:29 AM,1,0x,End of package execution.

The thing is, I configured the DestinationCreationType to "manual" and added my backup file name through coding to DestinationManualList ArrayList:

if (backupTask.DestinationManualList == null)
backupTask.DestinationManualList = new ArrayList();

backupTask.DestinationManualList.Add(m_SSISArgs.DatabaseBackupPath);

The objective is to create backup of the database with the file name I am giving. Do I have to set anyother property for this...

Catching an exception from a Web service task

Hi!

I am quite new using SSIS and I have a problem with catching an (SOAP) exception from a Web service task. Some times my web service task can fail and when the web service is failing, it is throwing an exception. When the task succeeds the result is being put into a variable, That part is not a problem.

But catching an exception is. I have tried to use a script task and tried to get exception from the dts object model. I have not yet succeeded on that. But it might be a possible way to go. A different approach might be creating an OnError event on my web service task which I can create a task when triggered. But I have not found any solution yet and I hope some people out there have done this before or have a solution on this.

Regards

Geir F

I forget to tell that I want the error description text from the exception that is thrown from the web service task because I want to log the errors. So what I hope is to have a script task that executes when web service fails and to write some code to catch the error description.

Current status on this is that the script task executes when the WS fails (red arrow). Nice. The web service returns an object, say TestOutput variable. When the WS succeeds, I can convert the object into a integer datatype and catch the value. But when it fails, I don't know to catch the error description. When executing the package, I can see the error description on th progress tab, so there must be a way for me to get the error too :-)

Regards

GF

Sunday, February 12, 2012

Casting...

I've got an ftp task that will be downloading a couple of files each night. today they're called

blah20060830blah

the date value in the middle changes each day. I'm trying to adjust this value with an expression. The expression doesn't want to cast my getdate function into a string that this property will accept. I know i'm missing something stupid.

Thank you

It'd help if you posted your expression and the error that you're getting.

-Jamie

|||Sorry

the expression
(DT_STR) GETDATE()

generates this:
Attempt to parse the expression "(DT_STR) GETDATE()" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

I'm no genius when it comes to making these expressions, and was unable to find a source on the msn site

Thanks again|||

All the source you need is in BOL. And in this case the syntax for the cast is given in the expression editor.

You need:

(DT_STR, 100, 1252)GETDATE()

-Jamie

|||What is BOL?

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?|||

killerless wrote:

What is BOL?

Sorry. Books Online. i.e. The help pages that you get with SQL Server.

killerless wrote:

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?

Hmmm...are you trying to add this as anew column or replace an existing one? If the latter, change it so that you are adding it as a new column.

-Jamie

|||Maybe I'm completely missing the boat here.

in an ftp task, there is a property called "Remote Path" As I understand, this designates what the path and filename of the remote file to be downloaded.

Here's my leap of understanding. I want that value to change daily, I'm assuming that I can define this using an expression. I will concat the parts of the string in the expression builder that don't change daily, to the part that i'm trying to generate right now (which is based on the date)

I am double clicking on the ftp task, setting appropriate properties, then going to the expression section and trying to set the remote path w/ an expression using the expression builder. I'm literally cutting and pasting what you typed in to the expression text area and trying to see if it will evaluate the expression as a string.

As far as I know there are no columns involved. (I will check out the BOL)

Thanks|||

Oh OK. Sorry, I thought you were in a Derived Column Component (which you are not).

Your approach is the corect one. its jsut going to take some debugging that's all.

The Expression Editor itself has some really useful visual aids as to the syntax of all the functions etc... Loom in the box in the top-right of the expressoin editor.

-Jamie

|||I think i'm getting there i will post when i figure this out...|||There's got to be a better way!!!!

DATEPART("weekday", GETDATE()) == 2 ?
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -3, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
)
:
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -1, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
)
+ "_today.gz.file.asc"

will successfully determine the last day of trading, and afix it to the middle of the string. Can you make temporary variables in these expressions that would probably cut this in half
|||How can I set this value to a variable, so that I can use it in other expressions?|||

killerless wrote:

How can I set this value to a variable, so that I can use it in other expressions?

Good idea!

There is a property of the variable called EvaluateAsExpression. Set this proeprty to false and then paste your expression into the Expression property.

I talk about this a bit here:

Using variables to store expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/12/05/2462.aspx)

Evaluating variables as expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/03/19/1163.aspx)

-Jamie

|||AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Is it possible to call a stored procedure? From a expression?

Thanks :)|||so...if the remote variable is now being set w/ an expression, why can't I leave the field blank? Aside from making lost of extra variables is there any advantage to putting these strings in variable derived from my date variable?

Thanks|||

killerless wrote:

AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Install Sp1 and you'll be able to

killerless wrote:

Is it possible to call a stored procedure? From a expression?

No! Sorry.

-Jamie

Casting...

I've got an ftp task that will be downloading a couple of files each night. today they're called

blah20060830blah

the date value in the middle changes each day. I'm trying to adjust this value with an expression. The expression doesn't want to cast my getdate function into a string that this property will accept. I know i'm missing something stupid.

Thank you

It'd help if you posted your expression and the error that you're getting.

-Jamie

|||Sorry

the expression
(DT_STR) GETDATE()

generates this:
Attempt to parse the expression "(DT_STR) GETDATE()" failed. The expression might contain an invalid token, an incomplete token, or an invalid element. It might not be well-formed, or might be missing part of a required element such as a parenthesis.

I'm no genius when it comes to making these expressions, and was unable to find a source on the msn site

Thanks again|||

All the source you need is in BOL. And in this case the syntax for the cast is given in the expression editor.

You need:

(DT_STR, 100, 1252)GETDATE()

-Jamie

|||What is BOL?

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?|||

killerless wrote:

What is BOL?

Sorry. Books Online. i.e. The help pages that you get with SQL Server.

killerless wrote:

I put your suggestion into the expression builder, but got the following error

Expression cannot be evaluated.

The expression "(DT_STR, 100, 1252)GETDATE()" has a result type of "DT_STR", which cannot be converted to a supported type.

Do I need to put more in the expression builder?

Hmmm...are you trying to add this as anew column or replace an existing one? If the latter, change it so that you are adding it as a new column.

-Jamie

|||Maybe I'm completely missing the boat here.

in an ftp task, there is a property called "Remote Path" As I understand, this designates what the path and filename of the remote file to be downloaded.

Here's my leap of understanding. I want that value to change daily, I'm assuming that I can define this using an expression. I will concat the parts of the string in the expression builder that don't change daily, to the part that i'm trying to generate right now (which is based on the date)

I am double clicking on the ftp task, setting appropriate properties, then going to the expression section and trying to set the remote path w/ an expression using the expression builder. I'm literally cutting and pasting what you typed in to the expression text area and trying to see if it will evaluate the expression as a string.

As far as I know there are no columns involved. (I will check out the BOL)

Thanks|||

Oh OK. Sorry, I thought you were in a Derived Column Component (which you are not).

Your approach is the corect one. its jsut going to take some debugging that's all.

The Expression Editor itself has some really useful visual aids as to the syntax of all the functions etc... Loom in the box in the top-right of the expressoin editor.

-Jamie

|||I think i'm getting there i will post when i figure this out...|||There's got to be a better way!!!!

DATEPART("weekday", GETDATE()) == 2 ?
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -3, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -3, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -3, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -3, getdate() ) ) )
)
:
"positions_01_CLARENROAD_" + (DT_WSTR,10)(DatePart("yyyy", DATEADD( "day", -1, getdate() ) ) ) +
(
DatePart("mm", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("mm", DATEADD( "day", -1, getdate() ) ) )
) +
(
DatePart("dd", DATEADD( "day", -1, getdate() ) ) < 10 ?
"0" + (DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
:
(DT_WSTR,10)(DatePart("dd", DATEADD( "day", -1, getdate() ) ) )
)
+ "_today.gz.file.asc"

will successfully determine the last day of trading, and afix it to the middle of the string. Can you make temporary variables in these expressions that would probably cut this in half
|||How can I set this value to a variable, so that I can use it in other expressions?|||

killerless wrote:

How can I set this value to a variable, so that I can use it in other expressions?

Good idea!

There is a property of the variable called EvaluateAsExpression. Set this proeprty to false and then paste your expression into the Expression property.

I talk about this a bit here:

Using variables to store expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/12/05/2462.aspx)

Evaluating variables as expressions
(http://blogs.conchango.com/jamiethomson/archive/2005/03/19/1163.aspx)

-Jamie

|||AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Is it possible to call a stored procedure? From a expression?

Thanks :)|||so...if the remote variable is now being set w/ an expression, why can't I leave the field blank? Aside from making lost of extra variables is there any advantage to putting these strings in variable derived from my date variable?

Thanks|||

killerless wrote:

AWESOME, thanks a lot, i'm looking forward to the day when the variable expression can be created w/ the expression builder. (I'd settle for a text area a this point)

Install Sp1 and you'll be able to

killerless wrote:

Is it possible to call a stored procedure? From a expression?

No! Sorry.

-Jamie