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

Tuesday, March 27, 2012

Calling Stored Procedure from an ActiveX task

I'm attempting to call a storedprocedure from within an ActiveX task in
a DTS and am getting a "Command Text was not set for the command
object" error. I have no problem if I replace the stored procedure call
with the actual SQL.

Is it possible to directly call a SP via an ActiveX task? If yes, could
somebody help me with the syntax please?

This is what I have currently have

Set Conn = CreateObject("ADODB.Connection")
SQL = "exec (MySP)"
set RLoop=conn.Execute(SQL)

do while (NOT RLoop.EOF)
msgbox RLoop(1)
RLoop.MoveNext

Loop

TIA

KarthikKarthik (karthiksmiles@.gmail.com) writes:
> I'm attempting to call a storedprocedure from within an ActiveX task in
> a DTS and am getting a "Command Text was not set for the command
> object" error. I have no problem if I replace the stored procedure call
> with the actual SQL.
> Is it possible to directly call a SP via an ActiveX task? If yes, could
> somebody help me with the syntax please?
> This is what I have currently have
> Set Conn = CreateObject("ADODB.Connection")
> SQL = "exec (MySP)"
> set RLoop=conn.Execute(SQL)

Cmd = CreateObject("ADODB.Command")
Cmd.ActiveConnection = Conn
Cmd.CommandType = adStoredProcedure
Cmd.CommandText = "MySP"
Set rs = cmd.Execute

Not that I have ever done it in DTS, but this should be like ADO anywhere
else.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Calling SSIS packages from within a Script task

Hello,

I was wondering if someone could point me in the direction of any sample code or documentation that allows you to execute SSIS packages from within a Script task?

In SQL Server 2000 DTS this was accomplished by instantiating the DTS.Package object and calling either the LoadFromSQLServer or LoadFromStorageFile method.

I have not been able to find any similiar logic in the SQL Server 2005 SSIS environment.

Any help would be greatly appreciated.

Thank you,

Gordon Radley

Sample code to execute a Package from Script task

Public Sub Main()
Dim pkg As String = "C:\SSISPackage\Package.dtsx"
Dim app As Application = New Application()
Dim p As Package = app.LoadPackage(pkg, Nothing)
p.Execute()
Dts.TaskResult = Dts.Results.Success
End Sub

Hope this helps.

Thanks,
Loonysan

|||

Yes - it definately helps. Thanks for the quick reply.

Do I need to add any additional references if I'm running this from within a Script task in SSIS?

Thanks again!

|||

The Runtime reference is sufficient. You'll want to make sure that you have the Imports statement in your code.

As you've notice, the "Load" methods are now more logically methods of the SSIS Application rather than of the Package itself.

For what it's worth, the documentation team is fleshing out the section on how packages can be loaded, executed, enumerated, and managed programmatically, and how their output can be loaded directly into other applications by using the DtsClient DLL.

-Doug

|||

Doug,

We have discovered issues with DTSClient. Basically you don't get much information out of it. e.g. If a package fails to validate the only message you get is "The package failed to validate" rather than which task failed to validate.

Darren has uncompiled the managed code and noticed some shortcoming in the way it hasbeen implemented. This is wa too low level for me but there are some easy fixes to this. I'm sure Darren would be happy to share his experiences I'm sure.

-Jamie

|||

Darren would never do such a thing, but either way this is not DtsClient. This thread is all about loading and executing a package, directly. For general info (not Jamie) DtsClient does this, but wraps it all up such that you can consume data exposed from the DataReader destination, see the BOL for samples of consuming SSIS from extrenal applications.

When loading and executing you can capture.events, by passing in an implementation of IDTSEvents, see the overloaded methods. If you don't then if anything goes wrong all you really know is it went wrong. By examining the events you get to know why. The package failed validation is a start, but it failed validation because it could not make a connection to SQL Server XYZ in Connection "ABC" is somewhat more helpfull. I strongly suggest you look further at this and implement IDTSEvents.

Jamie got the two confused because DtsClient does not do what I have suggested, and as such is really a nightmare to use real world. Being told something failed is better than not, but if you don't know what failed in a large package you can waste some serious amounts of time trying to find out, we have! For the DtsClient authrors to have not captued the events and exposed the information is just shockingly poor I find, and we no longer use it for that reason.

So to sum up, if you are loading and executing packages then have a look at the overloaded methods that accept IDTSEvents, it will be worth your while when things go wrong. If using DtsClient, I hope it doesn't go wrong for you!

=== Edited by DarrenSQLIS @. 04 Mar 2006 10:17 PM UTC===
Umm... re-reading the thread I now see Doug raised DtsClient, so I was more confused than anyone. Comments still stand, but I'm confused not Jamie.

|||

I have tried as you explained. Nothing happened. I have a top package from here I call another package which contains only script task.

In this script task, the package is called as below.

Dim Lpkg As String = "C:\User Entry Window\LongitudinalLoadingData.dtsx"

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Microsoft.SqlServer.Dts.Runtime.Application

Dim pL As Package = app.LoadPackage(Lpkg, Nothing)

If CStr(Dts.Variables("TypeOfSurvey").Value) = "L" Then

pL.Execute()

else

...Call another package.

End if.

I set the MsgBox message inside the LongitudinalLoadingData, but even this message will not appear. Do I need to add something?

Calling SSIS packages from within a Script task

Hello,

I was wondering if someone could point me in the direction of any sample code or documentation that allows you to execute SSIS packages from within a Script task?

In SQL Server 2000 DTS this was accomplished by instantiating the DTS.Package object and calling either the LoadFromSQLServer or LoadFromStorageFile method.

I have not been able to find any similiar logic in the SQL Server 2005 SSIS environment.

Any help would be greatly appreciated.

Thank you,

Gordon Radley

Sample code to execute a Package from Script task

Public Sub Main()
Dim pkg As String = "C:\SSISPackage\Package.dtsx"
Dim app As Application = New Application()
Dim p As Package = app.LoadPackage(pkg, Nothing)
p.Execute()
Dts.TaskResult = Dts.Results.Success
End Sub

Hope this helps.

Thanks,
Loonysan

|||

Yes - it definately helps. Thanks for the quick reply.

Do I need to add any additional references if I'm running this from within a Script task in SSIS?

Thanks again!

|||

The Runtime reference is sufficient. You'll want to make sure that you have the Imports statement in your code.

As you've notice, the "Load" methods are now more logically methods of the SSIS Application rather than of the Package itself.

For what it's worth, the documentation team is fleshing out the section on how packages can be loaded, executed, enumerated, and managed programmatically, and how their output can be loaded directly into other applications by using the DtsClient DLL.

-Doug

|||

Doug,

We have discovered issues with DTSClient. Basically you don't get much information out of it. e.g. If a package fails to validate the only message you get is "The package failed to validate" rather than which task failed to validate.

Darren has uncompiled the managed code and noticed some shortcoming in the way it hasbeen implemented. This is wa too low level for me but there are some easy fixes to this. I'm sure Darren would be happy to share his experiences I'm sure.

-Jamie

|||

Darren would never do such a thing, but either way this is not DtsClient. This thread is all about loading and executing a package, directly. For general info (not Jamie) DtsClient does this, but wraps it all up such that you can consume data exposed from the DataReader destination, see the BOL for samples of consuming SSIS from extrenal applications.

When loading and executing you can capture.events, by passing in an implementation of IDTSEvents, see the overloaded methods. If you don't then if anything goes wrong all you really know is it went wrong. By examining the events you get to know why. The package failed validation is a start, but it failed validation because it could not make a connection to SQL Server XYZ in Connection "ABC" is somewhat more helpfull. I strongly suggest you look further at this and implement IDTSEvents.

Jamie got the two confused because DtsClient does not do what I have suggested, and as such is really a nightmare to use real world. Being told something failed is better than not, but if you don't know what failed in a large package you can waste some serious amounts of time trying to find out, we have! For the DtsClient authrors to have not captued the events and exposed the information is just shockingly poor I find, and we no longer use it for that reason.

So to sum up, if you are loading and executing packages then have a look at the overloaded methods that accept IDTSEvents, it will be worth your while when things go wrong. If using DtsClient, I hope it doesn't go wrong for you!

=== Edited by DarrenSQLIS @. 04 Mar 2006 10:17 PM UTC===
Umm... re-reading the thread I now see Doug raised DtsClient, so I was more confused than anyone. Comments still stand, but I'm confused not Jamie.

|||

I have tried as you explained. Nothing happened. I have a top package from here I call another package which contains only script task.

In this script task, the package is called as below.

Dim Lpkg As String = "C:\User Entry Window\LongitudinalLoadingData.dtsx"

Dim app As Microsoft.SqlServer.Dts.Runtime.Application = New Microsoft.SqlServer.Dts.Runtime.Application

Dim pL As Package = app.LoadPackage(Lpkg, Nothing)

If CStr(Dts.Variables("TypeOfSurvey").Value) = "L" Then

pL.Execute()

else

...Call another package.

End if.

I set the MsgBox message inside the LongitudinalLoadingData, but even this message will not appear. Do I need to add something?

Thursday, March 22, 2012

Calling remote batch file using 'Execute process task'

I have a remote batch file on machine B that I need to execute using 'Execute process task' control from a package on machine A. The batch file uses pgp software and encrypts a file sitting on machine B itself. The reason why my batch file is sitting on machine B, is because the PGP software is on machine B.

If I execute the batch file by itself from machine B, the script runs fine. I refer the same batch file as a UNC path from my package on machine A. But that does not work since the 'Working directory' is still machine A. I can not set machine B's folder as the working dir because it does not accept UNC path. So I say, ok , let me map a path to that UNC location and map it as drive 'Z:\'. Certainly if I do so, I will be running the process on machine A and the batch file will look for the pgp software on machine A, and hence fail.

I have tried third party remote batch execution tools (PSEXEC) but have not had success, not because of SSIS limitations, but simply because the PGP executable when run through the PSEXEC tool, does not identify the location of the public keys on machine B and hence gives an encrytion failure.

How do I get the remote batch file to execute such that it executes with its own env? Is there a better remote execution tool I can try or are there any other features of SSIS I can use to get around this issue? I need the results of the batch file and hence do not want to make it an asyncronous process.

Thanks

Sumeet

PsExec will work for this purpose, and so will rsh and ssh implementation for Win32. Psexec is easier and you can use the "-e" parameter to configure alternate profile loading. Even if the environment from psexec were the minimal default user environment, just execute a remote command/script/executable which sets up the environment necessary prior to the pgp call.|||

Thanks. That helps. PsExec sends the alternate profile username/password as clear text. Can this be avoided in any way? I can not send account information to the PGP server as clear text. I am thinking about web service, but that has its own set of issues in executing a batch process, since the identiy of the executing process can not be changed (in 1.1)...

If someone can direct me to the user group where these questions can be better addressed, please let me know!

Thanks,

Sumeet

Tuesday, March 20, 2012

Calling DTS package with Send Mail object from VB

I have several processes that call DTS packages (SQL Sever 7) from VB6, and they work fine. The problem is that if there is a "Send mail" task in the package, it won't send the email if called from VB.

If I run the package directly through enterprise manager, the email gets sent, but if run through VB it does not.

Any ideas?

The vb code is below.

Thanks.

Lionel

Private Sub Command1_Click()

Dim objPackage As DTS.Package
Const DTSReposFlag_UseTrustedConnection = 256
Dim tServer As String

Set objPackage = New DTS.Package
tServer = "SQLBOX"
objPackage.LoadFromSQLServer tServer, "", "", DTSReposFlag_UseTrustedConnection, "", "", "", "dts_test"
objPackage.Execute
Set objPackage = Nothing

End SubPlease, post your DTS task that includes a call to xp_sendmail.|||I'm not actually sure how to post the DTS Package. When I script it through enterprise manager (Open the package and Save AS) then it saves in a unreadable format

(e.g. DZ b% o?`;\ D|Jkjìg).

Please could you let me know.

Thanks,

lwakersql

Calling child package out of process fails with Access Denied.

Has anyone ever used an Execute Package Task to call a child package, and the Execute Package Task's ExecuteOutOfProcess = True? Unless the account it runs under is an Administrator on the box, it fails for me with "Error 0x80070005 while loading package file "C:\program files\microsoft sql server\90\dts\Packages\ETL\Fact_SalesTransaction_Tracking.dtsx". Access is denied."

This is eating up hours and hours of my time, time we can't afford. Is anyone able to successfully call a child package out of process?

Unfortunately I have faced the same problem.

This only happens when you're executing the package from SQL Server Agent, or your account is of lower priveledges than anything but Administrator.

The only current solution to it, until ofcourse someone from microsoft fixes this problem, is to have your package run under the privelleges of a user in the Local Admin Group. Anything, and I mean anything less than that will cause you the same problem. I tried enabling ever single option, one by one, in the Local Security Policy, and nothing but adding the user that the SQL Server Agent executes in the context of, adding that user to the Local Admin group was the only solution.

Sorry for the bad news. But that's probably your only current solution as to what I know of.

|||

In this case it appears that the SQL Server Agent user account does not have access to the location of the package to be executed. If that access can be granted, then that should be effective.

However, you may not wish to give access to the Program Files folder - so you may wish to save the packages elsewhere in the file system. Alternatively, if file system access is tricky to provide, you may wish to store the packages in SQL Server and execute them from there. There are specific SSIS roles which can be used to control access to packages. See this interesting article from Kirk Haselden: http://www.sqlmag.com/Article/ArticleID/46723/sql_server_46723.html or this entry in Books Online: http://msdn2.microsoft.com/en-US/library/ms141053.aspx

A solution which enables package access with least privileges is certainly preferable to adding your Agent user to Local Admin.

Donald

Calling child package out of process fails with Access Denied.

Has anyone ever used an Execute Package Task to call a child package, and the Execute Package Task's ExecuteOutOfProcess = True? Unless the account it runs under is an Administrator on the box, it fails for me with "Error 0x80070005 while loading package file "C:\program files\microsoft sql server\90\dts\Packages\ETL\Fact_SalesTransaction_Tracking.dtsx". Access is denied."

This is eating up hours and hours of my time, time we can't afford. Is anyone able to successfully call a child package out of process?

Unfortunately I have faced the same problem.

This only happens when you're executing the package from SQL Server Agent, or your account is of lower priveledges than anything but Administrator.

The only current solution to it, until ofcourse someone from microsoft fixes this problem, is to have your package run under the privelleges of a user in the Local Admin Group. Anything, and I mean anything less than that will cause you the same problem. I tried enabling ever single option, one by one, in the Local Security Policy, and nothing but adding the user that the SQL Server Agent executes in the context of, adding that user to the Local Admin group was the only solution.

Sorry for the bad news. But that's probably your only current solution as to what I know of.

|||

In this case it appears that the SQL Server Agent user account does not have access to the location of the package to be executed. If that access can be granted, then that should be effective.

However, you may not wish to give access to the Program Files folder - so you may wish to save the packages elsewhere in the file system. Alternatively, if file system access is tricky to provide, you may wish to store the packages in SQL Server and execute them from there. There are specific SSIS roles which can be used to control access to packages. See this interesting article from Kirk Haselden: http://www.sqlmag.com/Article/ArticleID/46723/sql_server_46723.html or this entry in Books Online: http://msdn2.microsoft.com/en-US/library/ms141053.aspx

A solution which enables package access with least privileges is certainly preferable to adding your Agent user to Local Admin.

Donald

Monday, March 19, 2012

Calling a task within a task

Hi!
Is is possible to call a SQL task within an ActiveX script task?Hi!

Is is possible to call a SQL task within an ActiveX script task?

Look at SQLDMO in BOL.

Regards,

hmscott

Sunday, March 11, 2012

Calling a Data Pump task from DTS?

I have a vbscript to read all files from a directory and, if the file
is valid, I would like my DTS to process it. I tried using the
vbscript as an ActiveX workflow script in the DTS, but it does not
execute the data pump until it has completed looping through all the
files, so only the last file read is sucked into the database
(utilizing a global variable as the filename). Is there a way to
execute the data pump task from within the activex script? I can't
seem to find any documentation about executing a DTS task.

Basically, the workflow I want is:

1)Read files from directory (the number and names may change each
time). (done with vbs)

2)For each file, send it through the transformation into the database.

3)When the information is in the database, append a date to the file
and move it to the archive folder. (done with vbs)

If I am going about this the wrong way and you see something that is
not obvious to me, please let me know.

Thanks in advance!Hi

This may help:
http://www.sqldts.com/default.aspx?246

John

<noelle.bond@.gmail.com> wrote in message
news:1128110995.716126.283160@.g47g2000cwa.googlegr oups.com...
>I have a vbscript to read all files from a directory and, if the file
> is valid, I would like my DTS to process it. I tried using the
> vbscript as an ActiveX workflow script in the DTS, but it does not
> execute the data pump until it has completed looping through all the
> files, so only the last file read is sucked into the database
> (utilizing a global variable as the filename). Is there a way to
> execute the data pump task from within the activex script? I can't
> seem to find any documentation about executing a DTS task.
> Basically, the workflow I want is:
> 1)Read files from directory (the number and names may change each
> time). (done with vbs)
> 2)For each file, send it through the transformation into the database.
> 3)When the information is in the database, append a date to the file
> and move it to the archive folder. (done with vbs)
> If I am going about this the wrong way and you see something that is
> not obvious to me, please let me know.
> Thanks in advance!|||Thanks so much! I'll give it a try.|||noelle.bond@.gmail.com wrote:

> Thanks so much! I'll give it a try.

Just be forewarned, the DTS designer has a big disconnect between what
it shows you as the name of a DTS step and what actually needs to be
used in your VBScript code to refer to it as...

Thursday, March 8, 2012

Call Web Service From Script Task

I am trying to call a web service using the web service task and passing it variables, but even when I set variables to be Strings/any other data type, they always get passed out as objects. The call is then rejected based on the fact that there is no web service that accepts those parameter types. If there is a workaround to this problem, that would be great, otherwise I think I'm going to have to call the web services in a script task. Would someone please give me an example of the steps necessary to call a web service from the script task?

Thank you,

James Mac William

Can you instead post your code for us to review?|||currently I'm not using code to handle the service call. The IDE allows for a web service task to be called which I am using. It also allows for global variables to be declared within the package. You can set the global variables equal to any data type, but when they are passed, it is as an object rather than the datatype specified. My question is, can I convert that object to a string within the Web Service Task somehow, or is there a way to directly call the web service from the script task? I know that we can access pipeline elements such as variables from the script task if they are specified as input variables, perhaps there is a way to do this for web services too? I've already downloaded the wsdl file in another web service call that I was able to hardcode the string rather than pass a variable so it knows where the wsdl file is. Any thoughts? Help is much appreciated.|||

To call a web service from a script task, you need to create a wrapper assembly in Visual Studio first for the web service. Then you can add a reference to the wrapper assembly in the script task.

This has an example of calling the Reporting Services web service from a script task: http://mgarner.wordpress.com/2007/06/06/consuming-the-reporting-services-web-service-inside-ssis/

|||So I guess the important part in this example is instantiating the proxy object. I saw the code "wsdl.exe /language:VB /out:ReportService.vb http://[ReportServerName]/ReportServer/ReportService.asmx?WSDL" in the example site that you gave me, but I'm still a bit fuzzy on how to instantiate this proxy object. Can you go into a bit more detail on how to do this. IE Where would I type the above line? Thanks for your help!|||From the Visual Studio command prompt. Or you can start a new VB or C# project, and add a web reference.|||so if I'm in SSIS and I want to make this proxy object programmatically, I would create a script task and then type out what I mentioned before? It didnt seem to be taking that. Is there perhaps some reference to the pipeline that I have to make? I apologize if I'm catching on slowly, I'm somewhat new to SSIS, I really appreciate your help.|||

James Mac William wrote:

so if I'm in SSIS and I want to make this proxy object programmatically, I would create a script task and then type out what I mentioned before? It didnt seem to be taking that. Is there perhaps some reference to the pipeline that I have to make? I apologize if I'm catching on slowly, I'm somewhat new to SSIS, I really appreciate your help.

James,

The command-line tool wsdl.exe can generate C# or VB.Net classes that enable you to consume a web service. The code from the output of running that command can be copied/pasted into your script task for ease of use. or, you can use csc.exe to generate an assembly that you can add as a reference to your script task.

Regards

Jamie

|||it works! thank you thank you thank you, I'm grateful for everyone's help here!

Call Web Service From Script Task

This summary is not available. Please click here to view the post.

Wednesday, March 7, 2012

Call SSIS remotely to run exe task in server by C#

I would like to build a C# program to connect to a remote SQL2005 server.

Then call the server SSIS to run a .exe in the server (The .exe file already exist in the SQL2005 server)

I have refer to the following webpage http://www.codeproject.com/useritems/CallSSISFromCSharp.asp

I can connect to the SQL server by the "LoadFromSqlServer" method with SQL server login A/C.

However, the SSIS failed. I believe it should be due to the window authentication issue. During SSIS execution, the SQL server login A/C does not have the access right to run the .exe file

Could anyone suggest the solution?

Thanks.

If you are running the C# executable on your computer, it is not running the SSIS package on the server,it is executing it locally. So it would be running under your account, or it may be that the .exe on the server is not visible from your computer.

To actually run the package locally on the server, you'd need to create a web service, or use SQL Agent to run the package. This post from Michael Entin has more details: http://blogs.msdn.com/michen/archive/2007/03/22/running-ssis-package-programmatically.aspx

Sunday, February 19, 2012

Calculation for adjusting employee hours

I work for a telemarketing company. I have a table that looks like this:
Proj Emp Task Hours
A 1 sales 10
A 2 sales 15
A 3 sales 5
A 4 sales 20
A 5 QA 10
A 6 Audit 5
For project A, I need the total hours for tasks QA and Audit. In this case
it would be 15 hours. Then I need to take that 15 hours and evenly
distribute them among the rest of the records for project A and update the
adjHours for QA and Audit with 0s.
The results should look like this:
Proj Empl Task Hours AdjHours
A 1 sales 10 13.75
A 2 sales 15 18.75
A 3 sales 5 8.75
A 4 sales 20 23.75
A 5 QA 10 0
A 6 Audit 5 0
This needs to be an automated process. Can anyone help?
Thanks,
Ninel
Message posted via http://www.webservertalk.comTry,
update t1
set adjhours = hours + (
select isnull(sum(case when a.task = 'QA' or a.task = 'Audit' then a.hours
else 0 end) / nullif(sum(case when a.task = 'QA' or a.task = 'Audit' then 0
else 1 end), 0), 0)
from t1 as a
where a.proj = t1.proj
)
where
proj = 'A'
and task not in ('QA', 'Audit')
AMB
"ninel gorbunov via webservertalk.com" wrote:

> I work for a telemarketing company. I have a table that looks like this:
> Proj Emp Task Hours
> A 1 sales 10
> A 2 sales 15
> A 3 sales 5
> A 4 sales 20
> A 5 QA 10
> A 6 Audit 5
> For project A, I need the total hours for tasks QA and Audit. In this case
> it would be 15 hours. Then I need to take that 15 hours and evenly
> distribute them among the rest of the records for project A and update the
> adjHours for QA and Audit with 0s.
> The results should look like this:
> Proj Empl Task Hours AdjHours
> A 1 sales 10 13.75
> A 2 sales 15 18.75
> A 3 sales 5 8.75
> A 4 sales 20 23.75
> A 5 QA 10 0
> A 6 Audit 5 0
> This needs to be an automated process. Can anyone help?
> Thanks,
> Ninel
> --
> Message posted via http://www.webservertalk.com
>|||Have you considered doing this as a query rather than an UPDATE? That way
you preserve all the information but you can still display the required
values:
SELECT proj, emp, task,
CASE WHEN task IN ('QA','Audit') THEN 0 ELSE hours+
(SELECT SUM(CASE WHEN task IN ('QA','Audit') THEN hours END)
/CAST(SUM(CASE WHEN task NOT IN ('QA','Audit') THEN 1 END) AS REAL)
FROM TaskHours
WHERE proj = T.proj) END
FROM TaskHours AS T
Otherwise, just put the subquery into an UPDATE statement.
David Portas
SQL Server MVP
--|||Untested:
update tableName set hours =
case task
when 'QA' then 0
when 'Audit' then 0
else Hours + (select sum(hours)/count(hours) from tableName where task =
'sales' and Proj = 'A')
END
where Proj = 'A'
"ninel gorbunov via webservertalk.com" <forum@.nospam.webservertalk.com> wrote in
message news:dcb239fc53fe40a98c155bc2a26b3fd0@.SQ
webservertalk.com...
>I work for a telemarketing company. I have a table that looks like this:
> Proj Emp Task Hours
> A 1 sales 10
> A 2 sales 15
> A 3 sales 5
> A 4 sales 20
> A 5 QA 10
> A 6 Audit 5
> For project A, I need the total hours for tasks QA and Audit. In this case
> it would be 15 hours. Then I need to take that 15 hours and evenly
> distribute them among the rest of the records for project A and update the
> adjHours for QA and Audit with 0s.
> The results should look like this:
> Proj Empl Task Hours AdjHours
> A 1 sales 10 13.75
> A 2 sales 15 18.75
> A 3 sales 5 8.75
> A 4 sales 20 23.75
> A 5 QA 10 0
> A 6 Audit 5 0
> This needs to be an automated process. Can anyone help?
> Thanks,
> Ninel
> --
> Message posted via http://www.webservertalk.com|||You could write an AFTER INSERT, UPDATE, DELETE trigger to recalculate the
Hours for each project.
CREATE TRIGGER triggerName ON tableName AFTER INSERT, UPDATE, DELETE AS
BEGIN
UPDATE tableName
SET adjHours =
CASE
WHEN Task = 'sales' THEN Hours + b.distHours
ELSE 0.0
END
FROM
(SELECT Proj,
SUM(CASE
WHEN Task = 'sales' THEN 0.0
ELSE Hours
END) / CASE
WHEN SUM(CASE
WHEN Task = 'sales'
THEN 1
ELSE 0
END) = 0 THEN 1.0
ELSE SUM(CASE
WHEN Task = 'sales'
THEN 1.0
ELSE 0.0
END)
END AS distHours
FROM tableName
WHERE Proj IN (SELECT DISTINCT Proj FROM deleted
UNION SELECT DISTINCT Proj FROM
inserted)) b
WHERE tableName.Proj = b.Proj
END
I didn't test this, but it should point you in the right direction.
The extra case is necessary to prevent division by zero. I assume it is
possible for a QA or Audit record to be inserted before any sales records,
but since it forces adjHours to zero in that case, there isn't any need to
worry about the 1.0 in the denominator at that point. If there are any sale
s
records, the denominator will reflect the correct number of sales records.
If there aren't any, distHours will be ignored, so it doesn't matter what th
e
denominator is as long as it's not zero.
"ninel gorbunov via webservertalk.com" wrote:

> I work for a telemarketing company. I have a table that looks like this:
> Proj Emp Task Hours
> A 1 sales 10
> A 2 sales 15
> A 3 sales 5
> A 4 sales 20
> A 5 QA 10
> A 6 Audit 5
> For project A, I need the total hours for tasks QA and Audit. In this case
> it would be 15 hours. Then I need to take that 15 hours and evenly
> distribute them among the rest of the records for project A and update the
> adjHours for QA and Audit with 0s.
> The results should look like this:
> Proj Empl Task Hours AdjHours
> A 1 sales 10 13.75
> A 2 sales 15 18.75
> A 3 sales 5 8.75
> A 4 sales 20 23.75
> A 5 QA 10 0
> A 6 Audit 5 0
> This needs to be an automated process. Can anyone help?
> Thanks,
> Ninel
> --
> Message posted via http://www.webservertalk.com
>|||OOPS! I forgot the group by
CREATE TRIGGER triggerName ON tableName AFTER INSERT, UPDATE, DELETE AS
BEGIN
UPDATE tableName
SET adjHours =
CASE
WHEN Task = 'sales' THEN Hours + b.distHours
ELSE 0.0
END
FROM
(SELECT Proj,
SUM(CASE
WHEN Task = 'sales' THEN 0.0
ELSE Hours
END) / CASE
WHEN SUM(CASE
WHEN Task =
'sales' THEN 1
ELSE 0
END) = 0 THEN 1.0
ELSE SUM(CASE
WHEN Task = 'sales'
THEN 1.0
ELSE 0.0
END)
END AS distHours
FROM tableName
WHERE Proj IN (SELECT DISTINCT Proj FROM deleted
UNION SELECT DISTINCT Proj FROM inserted)
GROUP BY Proj) b
WHERE tableName.Proj = b.Proj
END
> I didn't test this, but it should point you in the right direction.
> The extra case is necessary to prevent division by zero. I assume it is
> possible for a QA or Audit record to be inserted before any sales records,
> but since it forces adjHours to zero in that case, there isn't any need to
> worry about the 1.0 in the denominator at that point. If there are any sa
les
> records, the denominator will reflect the correct number of sales records.
> If there aren't any, distHours will be ignored, so it doesn't matter what
the
> denominator is as long as it's not zero.
> "ninel gorbunov via webservertalk.com" wrote:
>|||This was great. Thank you, but now my manager just changed things around
for me.
Table1:
Proj Emp Task Hours
A 1 sales 10
A 2 sales 15
A 3 sales 5
A 4 sales 20
A 5 QA 10
A 6 Audit 5
Now he wants to calculate the percentage of each employee over the total
hours.
Emp1: 10/50 = 20%
Emp2: 15/50 = 30%
Emp3: 5/50 = 10%
Emp4: 20/50 = 40%
And then calculate what the adjusted hours should be:
Emp1: 20% * 15(Total QA and Audit) = 13
Emp2: 30% * 15(Total QA and Audit) = 19.5
Emp3: 10% * 15(Total QA and Audit) = 6.5
Emp4: 40% * 15(Total QA and Audit) = 26
Result Table:
Proj Empl Task Hours AdjHours
A 1 sales 10 13
A 2 sales 15 19.5
A 3 sales 5 6.5
A 4 sales 20 26
A 5 QA 10 0
A 6 Audit 5 0
Message posted via http://www.webservertalk.com

Thursday, February 16, 2012

Calculating the adjustment of employee hours

I work for a telemarketing company. I have a table that looks like
this:
Project Emp Task Hours
A 1 sales 10
A 2 sales 15
A 3 sales 5
A 4 sales 20
A 5 QA 10
A 6 Audit 5
For project A, I need the total hours for tasks QA and Audit. In this
case it would be 15 hours. Then I need to take that 15 hours and
evenly distribute them among the rest of the records for project A
and update the adjHours for QA and Audit with 0s.
The results should look like this:
Project Emp Task Hours AdjHours
A 1 sales 10 13.75
A 2 sales 15 18.75
A 3 sales 5 8.75
A 4 sales 20 23.75
A 5 QA 10 0
A 6 Audit 5 0
This needs to be an automated process. Can anyone help?
Thanks,
NinelHi
Maybe
SELECT Project, Emp, Task,
CASE WHEN Task in ('Audit','QA') THEN 0 ELSE HOURS + ( SELECT CAST(SUM(CASE
WHEN Task in ('Audit','QA') THEN Hours ELSE 0 END) AS DECIMAL(8,3))/SUM(CASE
WHEN Task in ('Audit','QA') THEN 0 ELSE 1 END)
FROM #ProjectTime ) END AS Hours
FROM #ProjectTime
You would need to be careful of divide by zero errors and you may have to
group the sumations and/ or it change to use a derived table.
John
"ninel" wrote:

> I work for a telemarketing company. I have a table that looks like
> this:
> Project Emp Task Hours
> A 1 sales 10
> A 2 sales 15
> A 3 sales 5
> A 4 sales 20
> A 5 QA 10
> A 6 Audit 5
> For project A, I need the total hours for tasks QA and Audit. In this
> case it would be 15 hours. Then I need to take that 15 hours and
> evenly distribute them among the rest of the records for project A
> and update the adjHours for QA and Audit with 0s.
> The results should look like this:
> Project Emp Task Hours AdjHours
> A 1 sales 10 13.75
> A 2 sales 15 18.75
> A 3 sales 5 8.75
> A 4 sales 20 23.75
> A 5 QA 10 0
> A 6 Audit 5 0
> This needs to be an automated process. Can anyone help?
> Thanks,
> Ninel
>|||http://support.microsoft.com/newsgr...n-us&sloc=en-us
AMB
"ninel" wrote:

> I work for a telemarketing company. I have a table that looks like
> this:
> Project Emp Task Hours
> A 1 sales 10
> A 2 sales 15
> A 3 sales 5
> A 4 sales 20
> A 5 QA 10
> A 6 Audit 5
> For project A, I need the total hours for tasks QA and Audit. In this
> case it would be 15 hours. Then I need to take that 15 hours and
> evenly distribute them among the rest of the records for project A
> and update the adjHours for QA and Audit with 0s.
> The results should look like this:
> Project Emp Task Hours AdjHours
> A 1 sales 10 13.75
> A 2 sales 15 18.75
> A 3 sales 5 8.75
> A 4 sales 20 23.75
> A 5 QA 10 0
> A 6 Audit 5 0
> This needs to be an automated process. Can anyone help?
> Thanks,
> Ninel
>

Sunday, February 12, 2012

Calculating a percentage using aggregate task

Hi,

I have a column called QTY and I need to calculate the percentage for each row based on the total sum of the column. They are all decimals. I have an OLE DB source that is reading the table used an aggregate task using the QTY column with operation SUM and called the output SUM OF QTY. Then I have a Derived Column task that takes the QTY column / SUM OF QTY * 100 to create the percentage. My numbers are not coming out correctly and when I put a data viewer from the aggregate task, it shows the same number for both columns:

QTY SUM OF QTY

0.01833 0.01833 (this should be the sum of all the decimals in the QTY col)

What am I doing wrong?

Thanks in advance!

Isabelle

You might have to use a multitask component to get this to work. The aggregate transformation does not pass fields through. So from the multitask output, you can take one path to the aggregate, and another to a sort. Take the output of the aggregate and put it in a sort as well. Then, take the two sorts and hook them up with a merge join on the common keys. Then, you'll have your original data, along with the aggregate column.|||

Thanks for your response. I tried what you suggested and I still could not get it to work. Even when I created a sort column for both and then used a join merge, I still got the same amound in both columns. I ended up doing the conversion using Execute SQL task and saved the output as a variable and then just called the variable in a derived column and that worked.

Isabelle

Calculating a percentage using aggregate task

Hi,

I have a column called QTY and I need to calculate the percentage for each row based on the total sum of the column. They are all decimals. I have an OLE DB source that is reading the table used an aggregate task using the QTY column with operation SUM and called the output SUM OF QTY. Then I have a Derived Column task that takes the QTY column / SUM OF QTY * 100 to create the percentage. My numbers are not coming out correctly and when I put a data viewer from the aggregate task, it shows the same number for both columns:

QTY SUM OF QTY

0.01833 0.01833 (this should be the sum of all the decimals in the QTY col)

What am I doing wrong?

Thanks in advance!

Isabelle

You might have to use a multitask component to get this to work. The aggregate transformation does not pass fields through. So from the multitask output, you can take one path to the aggregate, and another to a sort. Take the output of the aggregate and put it in a sort as well. Then, take the two sorts and hook them up with a merge join on the common keys. Then, you'll have your original data, along with the aggregate column.|||

Thanks for your response. I tried what you suggested and I still could not get it to work. Even when I created a sort column for both and then used a join merge, I still got the same amound in both columns. I ended up doing the conversion using Execute SQL task and saved the output as a variable and then just called the variable in a derived column and that worked.

Isabelle