Showing posts with label generates. Show all posts
Showing posts with label generates. Show all posts

Monday, March 19, 2012

Calling a stored procedure that inserts records and generates an output parameter

I will be calling a stored procedure in SQL Server from SSIS. The stored procedure inserts records in a table by accepting input parameters. In the process, it also generates an output parameter that it passes as part of the parameters defined inside the stored procedure. The output parameter value acts as the primary key value for the record inserted using the stored procedure.

How can I call this stored procedure in SSIS? This is just one of the n steps as I will be extracting the output parameter generated by this stored procedure for the succeeding steps.

The Execute SQL Task sounds best suited to this scenario: http://www.sqlis.com/default.aspx?58

-Jamie

|||I've already tried that but I need to pass multiple records in the Execute SQL task, not just one.|||

So you're going to be executing the SP for every record in the pipeline? If that is the case then the OLE DB Command transform will be of help but I would recommend you find an alternate means of doing this. Executing a seperate query for each row is not considered great practice.

-Jamie

|||How do you use the OLEDB Command Transform? Actually, I just created a simple app to do the trick. The thing is, I cannot do anything about it. I just need to migrate existing records into a new database. I need to use the existing SP to insert the records from an Oracle database into the new SQL Server database because they are of different schemas and design.

Sunday, March 11, 2012

Calling a function inside of a function is not allowed in sql server?

We have a stored procedure that generates a unique random integer which uses
the RAND function. For data columns, you can invoke a function to create a
default value .e.x.: NEWID(). I would like to call a function that will
perform the same operations as the stored procedure.
The sql guru here says he tried to make our stored prodecure a function but
wasn't able to because sql server2k wouldn't allow him to use RAND inside
the function. Does anyone know of any workarounds, will future verions of
sql server allow this?
Thx in advance.Pass RAND() into the function (this is much the same as GETDATE()). Look up
DETERMINISTIC and NONDETERMINISTIC. See http://www.aspfaq.com/2439
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Hasani (remove nospam from address)" <hblackwell@.n0sp4m.popstick.com> wrote
in message news:uK2Qeh1lEHA.3496@.TK2MSFTNGP12.phx.gbl...
> We have a stored procedure that generates a unique random integer which
uses
> the RAND function. For data columns, you can invoke a function to create a
> default value .e.x.: NEWID(). I would like to call a function that will
> perform the same operations as the stored procedure.
> The sql guru here says he tried to make our stored prodecure a function
but
> wasn't able to because sql server2k wouldn't allow him to use RAND inside
> the function. Does anyone know of any workarounds, will future verions of
> sql server allow this?
> Thx in advance.
>|||Works great, THX!!!!!!!
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uWRx%23m1lEHA.3432@.TK2MSFTNGP14.phx.gbl...
> Pass RAND() into the function (this is much the same as GETDATE()). Look
> up
> DETERMINISTIC and NONDETERMINISTIC. See http://www.aspfaq.com/2439
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Hasani (remove nospam from address)" <hblackwell@.n0sp4m.popstick.com>
> wrote
> in message news:uK2Qeh1lEHA.3496@.TK2MSFTNGP12.phx.gbl...
>> We have a stored procedure that generates a unique random integer which
> uses
>> the RAND function. For data columns, you can invoke a function to create
>> a
>> default value .e.x.: NEWID(). I would like to call a function that will
>> perform the same operations as the stored procedure.
>> The sql guru here says he tried to make our stored prodecure a function
> but
>> wasn't able to because sql server2k wouldn't allow him to use RAND inside
>> the function. Does anyone know of any workarounds, will future verions of
>> sql server allow this?
>> Thx in advance.
>>
>

Calling a function inside of a function is not allowed in sql server?

We have a stored procedure that generates a unique random integer which uses
the RAND function. For data columns, you can invoke a function to create a
default value .e.x.: NEWID(). I would like to call a function that will
perform the same operations as the stored procedure.
The sql guru here says he tried to make our stored prodecure a function but
wasn't able to because sql server2k wouldn't allow him to use RAND inside
the function. Does anyone know of any workarounds, will future verions of
sql server allow this?
Thx in advance.
Pass RAND() into the function (this is much the same as GETDATE()). Look up
DETERMINISTIC and NONDETERMINISTIC. See http://www.aspfaq.com/2439
http://www.aspfaq.com/
(Reverse address to reply.)
"Hasani (remove nospam from address)" <hblackwell@.n0sp4m.popstick.com> wrote
in message news:uK2Qeh1lEHA.3496@.TK2MSFTNGP12.phx.gbl...
> We have a stored procedure that generates a unique random integer which
uses
> the RAND function. For data columns, you can invoke a function to create a
> default value .e.x.: NEWID(). I would like to call a function that will
> perform the same operations as the stored procedure.
> The sql guru here says he tried to make our stored prodecure a function
but
> wasn't able to because sql server2k wouldn't allow him to use RAND inside
> the function. Does anyone know of any workarounds, will future verions of
> sql server allow this?
> Thx in advance.
>
|||Works great, THX!!!!!!!
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uWRx%23m1lEHA.3432@.TK2MSFTNGP14.phx.gbl...
> Pass RAND() into the function (this is much the same as GETDATE()). Look
> up
> DETERMINISTIC and NONDETERMINISTIC. See http://www.aspfaq.com/2439
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Hasani (remove nospam from address)" <hblackwell@.n0sp4m.popstick.com>
> wrote
> in message news:uK2Qeh1lEHA.3496@.TK2MSFTNGP12.phx.gbl...
> uses
> but
>

Sunday, February 12, 2012

Calculating durations between multiple time stamps

Hi,
I have a problem with calculation call durations in my call logging
database.
My application generates a lock event when a call is opened and an
unlock event when it is put on hold.
These are stored in my CallEvent table (CallID int, EventType
varchar(4), EventComplete DateTime).
There may be multiple lock/unlock events for a call.
Each hour a job runs to populate a reporting table with the duration of
calls.
Currently the job uses the min and max lock/unlock times, this is
incorrect because there may be a substantial delay between lock/unlock
pairs.
I need to generate the call duration using the sum of the times between
lock/unlock pairs.
I don't want to use a cursor for performance reasons, but I can't think
how to calculate the result without putting some kind of loop in.
e.g. Select CallID, EventType, EventComplete
into #CallDuration
from CallEvent
where EventType in ('Unlock', 'Lock')
order by CallID, EventComplete
Then select the top 2 from the temp table, add it to a variable, drop
the 2 rows from the temp table and loop until the callID changes.
Update the reports table and move on to the next CallID.
While this will work it just seems inelegant and possibly slow.
I just can't see how I could sum the durations between lock/unlock pairs.
Assistance appreciated.
MartinUntested:
SELECT CallID, SUM(DATEDIFF(ss, LockStart, LockEnd)) AS TotalCallLength
FROM(
SELECT c1.CallID, c1.EventComplete AS LockStart,
(SELECT MIN(c2.EventComplete) FROM CallEvent c2
WHERE c2.EventType = 'UnLock' AND c2.CallID = c1.CallID
AND c2.EventComplete > c1.EventComplete ) AS LockEnd
FROM CallEvent c1
WHERE c1.EventType = 'Lock'
) a
GROUP BY CallID
Jacco Schalkwijk
SQL Server MVP
"Martin Selway" <mselway@.freeuk.com> wrote in message
news:%23ZUtZTIKFHA.1476@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I have a problem with calculation call durations in my call logging
> database.
> My application generates a lock event when a call is opened and an unlock
> event when it is put on hold.
> These are stored in my CallEvent table (CallID int, EventType varchar(4),
> EventComplete DateTime).
> There may be multiple lock/unlock events for a call.
> Each hour a job runs to populate a reporting table with the duration of
> calls.
> Currently the job uses the min and max lock/unlock times, this is
> incorrect because there may be a substantial delay between lock/unlock
> pairs.
> I need to generate the call duration using the sum of the times between
> lock/unlock pairs.
> I don't want to use a cursor for performance reasons, but I can't think
> how to calculate the result without putting some kind of loop in.
> e.g. Select CallID, EventType, EventComplete
> into #CallDuration
> from CallEvent
> where EventType in ('Unlock', 'Lock')
> order by CallID, EventComplete
> Then select the top 2 from the temp table, add it to a variable, drop the
> 2 rows from the temp table and loop until the callID changes.
> Update the reports table and move on to the next CallID.
> While this will work it just seems inelegant and possibly slow.
> I just can't see how I could sum the durations between lock/unlock pairs.
> Assistance appreciated.
> Martin
>|||Thanks Jacco,
my colleague came up with a similar soln. we'll test it to see if it works.
Martin
Jacco Schalkwijk wrote:
> Untested:
> SELECT CallID, SUM(DATEDIFF(ss, LockStart, LockEnd)) AS TotalCallLength
> FROM(
> SELECT c1.CallID, c1.EventComplete AS LockStart,
> (SELECT MIN(c2.EventComplete) FROM CallEvent c2
> WHERE c2.EventType = 'UnLock' AND c2.CallID = c1.CallID
> AND c2.EventComplete > c1.EventComplete ) AS LockEnd
> FROM CallEvent c1
> WHERE c1.EventType = 'Lock'
> ) a
> GROUP BY CallID
>