Showing posts with label tasks. Show all posts
Showing posts with label tasks. Show all posts

Monday, March 26, 2012

Duplicate Information with Different IDs

Duplicate Information with Different IDs
I am trying to sum monthly hours for wly timecards which have multiple
line items as tasks, but I am retrieving duplicate entries.
This is because a timecard can have a timecard_type of "r" (regular), or a
timecard_type of "c" (corrected).
If the timecard is corrected, the original with the timecard_type of "r"
still exists, but both time cards with duplicate information, have different
timecard IDs.
WHERE tc_type = 'r'
OR tc_type = 'c'
doesn't help me, so how can I get a monthly total of regular
timecards(timecard_type = 'r'), & corrected (timecard_type = 'c'),
and the original regular timecard is not returned, if it has been corrected.
I've got to think there's some way to use the timecard IDs.
When trying to use an "IF...ELSE", I get the error "Subquery returned more
than 1 value" because of the multiple line items.
Can someone please help?
p.s. There's a duplicate thread in SQL Server Reporting Services. Sorry for
the mis-hit.Untested, and guessing at your schema, but something like this should
do the trick:
SELECT timecard_id, SUM(hours)
FROM timecards_table
WHERE tc_type = 'c'
OR (tc_type = 'r' AND timecard_id NOT IN (SELECT timecard_id FROM
timecards_table WHERE tc_type = 'c'))
GROUP BY timecard_id|||You need to post DDL and some sample data.
http://www.aspfaq.com/etiquette.asp?id=5006
The answer is you have to look at other columns to identify duplicate time
cards in order to exclude the ones that have been corrected. Without
knowing your data structures we can only guess.
I'll assume your table looks like this:
Create table timecard
(
timecardID integer primary key not null
, EmployeeID varchar(10) not null
, PayEndDate datetime not null
, Workdate datetime not null
, EarningCode varchar(3) not null
, HoursWorked decimal (4,2) not null
, timecard_type char(1) not null
)
I will also assume that you can have only one valid timecard per employee
per workdate. If this is not reality, adjust the criteria to match your
level of uniqueness. You can put the following logic into a view and then
report against it.
select a.employeeID
, a.payenddate
, a.workdate
, a.earningscode
, a.hoursworked
from timecard a
where a.timecard_type = 'c'
or
(
a.timecard_type = 'r'
and not exists (
select 1 from timecard b
where b.employeeid = a.employeeid
and b.payenddate = a.payenddate
and b.workdate = a.workdate
and b.timecard_type = 'c'
)
)
"JDArsenault" <JDArsenault@.discussions.microsoft.com> wrote in message
news:FD43BC50-2072-4A2B-BAE2-3B49CA07EF48@.microsoft.com...
> Duplicate Information with Different IDs
> I am trying to sum monthly hours for wly timecards which have multiple
> line items as tasks, but I am retrieving duplicate entries.
> This is because a timecard can have a timecard_type of "r" (regular), or a
> timecard_type of "c" (corrected).
> If the timecard is corrected, the original with the timecard_type of "r"
> still exists, but both time cards with duplicate information, have
different
> timecard IDs.
> WHERE tc_type = 'r'
> OR tc_type = 'c'
> doesn't help me, so how can I get a monthly total of regular
> timecards(timecard_type = 'r'), & corrected (timecard_type = 'c'),
> and the original regular timecard is not returned, if it has been
corrected.
> I've got to think there's some way to use the timecard IDs.
> When trying to use an "IF...ELSE", I get the error "Subquery returned more
> than 1 value" because of the multiple line items.
> Can someone please help?
> p.s. There's a duplicate thread in SQL Server Reporting Services. Sorry
for
> the mis-hit.|||there are many ways to skin a cat, for instance:
create table #timecard(emp_id int not null,
timecard_type char(1) not null check(timecard_type in ('r','c')),
hours int not null,
unique(emp_id, timecard_type))
go
insert into #timecard values(1,'r',40)
insert into #timecard values(1,'c',32)
insert into #timecard values(2,'r',40)
go
select r.emp_id, coalesce(c.hours, r.hours)
from
(select emp_id, hours from #timecard where timecard_type='r') r
left outer join
(select emp_id, hours from #timecard where timecard_type='c') c
on r.emp_id = c.emp_id
emp_id
-- --
1 32
2 40
(2 row(s) affected)|||Once I had all the information in a view, I used this piece in a dataset
query & it worked great! Thanks
"Tracy McKibben" wrote:

> Untested, and guessing at your schema, but something like this should
> do the trick:
> SELECT timecard_id, SUM(hours)
> FROM timecards_table
> WHERE tc_type = 'c'
> OR (tc_type = 'r' AND timecard_id NOT IN (SELECT timecard_id FROM
> timecards_table WHERE tc_type = 'c'))
> GROUP BY timecard_id
>|||Thank you fro reminding me of your refered link. I used a derivative of this
& it worked. Thanks
"Jim Underwood" wrote:

> You need to post DDL and some sample data.
> http://www.aspfaq.com/etiquette.asp?id=5006
> The answer is you have to look at other columns to identify duplicate time
> cards in order to exclude the ones that have been corrected. Without
> knowing your data structures we can only guess.
> I'll assume your table looks like this:
> Create table timecard
> (
> timecardID integer primary key not null
> , EmployeeID varchar(10) not null
> , PayEndDate datetime not null
> , Workdate datetime not null
> , EarningCode varchar(3) not null
> , HoursWorked decimal (4,2) not null
> , timecard_type char(1) not null
> )
> I will also assume that you can have only one valid timecard per employee
> per workdate. If this is not reality, adjust the criteria to match your
> level of uniqueness. You can put the following logic into a view and then
> report against it.
> select a.employeeID
> , a.payenddate
> , a.workdate
> , a.earningscode
> , a.hoursworked
> from timecard a
> where a.timecard_type = 'c'
> or
> (
> a.timecard_type = 'r'
> and not exists (
> select 1 from timecard b
> where b.employeeid = a.employeeid
> and b.payenddate = a.payenddate
> and b.workdate = a.workdate
> and b.timecard_type = 'c'
> )
> )
> "JDArsenault" <JDArsenault@.discussions.microsoft.com> wrote in message
> news:FD43BC50-2072-4A2B-BAE2-3B49CA07EF48@.microsoft.com...
> different
> corrected.
> for
>
>|||I got it to work using something else, but I have another place where I can
use this. Thanks
"Alexander Kuznetsov" wrote:

> there are many ways to skin a cat, for instance:
> create table #timecard(emp_id int not null,
> timecard_type char(1) not null check(timecard_type in ('r','c')),
> hours int not null,
> unique(emp_id, timecard_type))
> go
> insert into #timecard values(1,'r',40)
> insert into #timecard values(1,'c',32)
> insert into #timecard values(2,'r',40)
> go
> select r.emp_id, coalesce(c.hours, r.hours)
> from
> (select emp_id, hours from #timecard where timecard_type='r') r
> left outer join
> (select emp_id, hours from #timecard where timecard_type='c') c
> on r.emp_id = c.emp_id
> emp_id
> -- --
> 1 32
> 2 40
> (2 row(s) affected)
>

Duplicate Information with Different IDs

I am trying to sum monthly hours for weekly timecards which have multiple
line items as tasks, but I am retrieving duplicate entries.
This is because a timecard can have a timecard_type of "r" (regular), or a
timecard_type of "c" (corrected).
If the timecard is corrected, the original with the timecard_type of "r"
still exists, but both time cards with duplicate information, have different
timecard IDs.
WHERE tc_type = 'r'
OR tc_type = 'c'
doesn't help me, so how can I get a monthly total of regular
timecards(timecard_type = 'r'), & corrected (timecard_type = 'c'),
and the original regular timecard is not returned, if it has been corrected.
I've got to think there's some way to use the timecard IDs.
When trying to use an "IF...ELSE", I get the error "Subquery returned more
than 1 value" because of the multiple line items.
Can someone please help?
Thanks much.ok. this uses a bit of old school sql but i hope it will help you
i use subqueries and join.
first to find out if a task has a corrected hour report for a certain
week
and second to retrieve the correct report for the task
here goes...
if your table , WEEKLY_CARDS , has the following fields :
EMPID , YEAR, WEEK_OF_YEAR , TASKID , HOURS , CARDTYPE
and EMPID , YEAR, WEEK_OF_YEAR , TASKID , CARDTYPE are the business
unique key in the table.
run the following sql
select myTable.*
from
WEEKLY_CARDS as myTable
inner join
(select
regular.empid
,regular.year
,regular.week_of_year
,regular.taskid
,isnull(corrected.cardtype,regular.cardtype) as cardtypeToUse
from
(select empid , year , week_of_year , taskid , cardtype
from WEEKLY_CARDS
where cardtype = 'r'
) as regular
left outer join
(select empid , year , week_of_year , taskid , cardtype
from WEEKLY_CARDS
where cardtype = 'c'
) as corrected
on regular.empid = corrected.empid
,regular.year = corrected.year
,regular.week_of_year = corrected.week_of_year
,regular.taskid = corrected.taskid
) whatToUse
on
on mytable.empid = whatToUse.empid
,mytable.year = whatToUse.year
,mytable.week_of_year = whatToUse.week_of_year
,mytable.taskid = whatToUse.taskid
,cardtype.cardtype= whatToUse.cardtypeToUse
if you use more than 1 table (maybe u have a CARDS table) then adjust
the sql accordingly. also, if you need information about a certain week
add the appropriate WHERE clauses
hope this helps
lior
JDArsenault wrote:
> I am trying to sum monthly hours for weekly timecards which have multiple
> line items as tasks, but I am retrieving duplicate entries.
> This is because a timecard can have a timecard_type of "r" (regular), or a
> timecard_type of "c" (corrected).
> If the timecard is corrected, the original with the timecard_type of "r"
> still exists, but both time cards with duplicate information, have different
> timecard IDs.
> WHERE tc_type = 'r'
> OR tc_type = 'c'
> doesn't help me, so how can I get a monthly total of regular
> timecards(timecard_type = 'r'), & corrected (timecard_type = 'c'),
> and the original regular timecard is not returned, if it has been corrected.
> I've got to think there's some way to use the timecard IDs.
> When trying to use an "IF...ELSE", I get the error "Subquery returned more
> than 1 value" because of the multiple line items.
> Can someone please help?
> Thanks much.

Sunday, February 26, 2012

DTSRun causes The Memory could not be "read" application error

Hi,

I've got this dts package in sql server 2000 sp4 that has several
transformation tasks with an oracle database (10g) as the destination.
The package executes successfully when run through the dts designer but
when run using dtsrun, I get the following error at the completion of
all tasks in the dts package. The data inserts into the oracle database
but i always get this Application error

The Instruction at "0x7c8327f9" referenced memory at "Oxffffffff". The
memory could not be "read"

Does anyone know how I can fix this?

Thanks
LynHi

I am not sure why this should happen but you may want to check that your
arguements are correct http://support.microsoft.com/?kbid=308801 and that
you can the same versions of MDAC on the machine it is running on and that
it is consistent (see MDAC component checker http://tinyurl.com/6gsv )
http://support.microsoft.com/?kbid=255900

John
<lyn.duong@.gmail.com> wrote in message
news:1130286935.981909.22760@.g43g2000cwa.googlegro ups.com...
> Hi,
> I've got this dts package in sql server 2000 sp4 that has several
> transformation tasks with an oracle database (10g) as the destination.
> The package executes successfully when run through the dts designer but
> when run using dtsrun, I get the following error at the completion of
> all tasks in the dts package. The data inserts into the oracle database
> but i always get this Application error
> The Instruction at "0x7c8327f9" referenced memory at "Oxffffffff". The
> memory could not be "read"
> Does anyone know how I can fix this?
> Thanks
> Lyn|||Hi John,

The mdac problem is relevant to sql server 7.0 and I've checked the
other kb. I don't pass any arguments. I have already got the latest
service pack installed for sql server 2000.

Lyn

John Bell wrote:
> Hi
> I am not sure why this should happen but you may want to check that your
> arguements are correct http://support.microsoft.com/?kbid=308801 and that
> you can the same versions of MDAC on the machine it is running on and that
> it is consistent (see MDAC component checker http://tinyurl.com/6gsv )
> http://support.microsoft.com/?kbid=255900
> John
> <lyn.duong@.gmail.com> wrote in message
> news:1130286935.981909.22760@.g43g2000cwa.googlegro ups.com...
> > Hi,
> > I've got this dts package in sql server 2000 sp4 that has several
> > transformation tasks with an oracle database (10g) as the destination.
> > The package executes successfully when run through the dts designer but
> > when run using dtsrun, I get the following error at the completion of
> > all tasks in the dts package. The data inserts into the oracle database
> > but i always get this Application error
> > The Instruction at "0x7c8327f9" referenced memory at "Oxffffffff". The
> > memory could not be "read"
> > Does anyone know how I can fix this?
> > Thanks
> > Lyn

Sunday, February 19, 2012

DTS!! Plese help!

I've been stuck with this for a week and I seriously need help!

I have a DTS package with only 2 tasks, an ExecuteSqlTask that loads global variables and a TransformDataTask.

The TransformDataTask "source" is a query over one table, and the "destination" is another table. The transformation itself is an ActivexScript, written in VBscript, that performs several checks over source data and retrieves "data warehouse keys" from the DW tables using lookups.

So far, everything seems ok.
If I test the transformation it works fine, and produces a text output that (for testing purposes) I have tried to insert into the destination table, and this also works!!!!
But when I try to execute the package via Enterprise Manager the execution halts. I've set "Row Count Step" to 1, in order to guess wich line had the problem. This number changes but independetly from sorting data. Execution halts when less than 100 rows have been processed!!!! It actually doesn't halt, it says "Running" but stays like that for even days!!!!!!

Ok, I' ll send the code.
All the lookups "retrieve" values, except "actualiza_valores" that performs an update.

Any ideas would be apreciated!!!!
thanks in advance
lorena

Function Main()

Dim ASIGNADA
Dim CONFIRMADA
Dim NO_REALIZADA
Dim ULTERIOR
Dim PRIMERA_VEZ
Dim PROGRAMADA
Dim NO_PROGRAMADA
Dim NUEVA
Dim REPETIDA
Dim fecha
Dim TIEMPO_ESPERA
Dim cantAnio
Dim edad
Dim msg

ASIGNADA=0
CONFIRMADA=0
NO_REALIZADA=0
ULTERIOR = 0
PRIMERA_VEZ=0
NUEVA = 0
REPETIDA=0
TIEMPO_ESPERA= 0
PROGRAMADA = 0
NO_PROGRAMADA = 0
cantAnio = 0
msg="hola"

'Hay que ver si hay una consulta para el mismo paciente, profesional, servicio y fecha.
'Si es asi se actualizan las medidas de ese hecho.
'El tiempo de espera sera el promedio de los tiempos de espera

fecha = DTSLookups("get_id_fecha").Execute(DTSSource("fecha_consulta"))
servicio =DTSLookups("get_id_servicio").Execute(DTSSource("servicio_clave"))

If IsNull(DTSSource("profesional_clave")) Then
msg="El profesional llego NULL"
DTSLookups("set_entrada_log").Execute(msg)
profesional = DTSLookups("get_id_profesional").Execute(-1)
Else
profesional = DTSLookups("get_id_profesional").Execute(DTSSource("profesional_clave"))
End If
If IsEmpty(profesional) Then
msg="El profesional "&CStr(DTSSource("profesional_clave"))&" no esta en la dimension"
' DTSPackageLog.WriteStringToLog msg
profesional = DTSLookups("get_id_profesional").Execute(-1)
End If

cliente=DTSLookups("get_id_cliente").Execute(DTSSource("cliente_clave"))
If IsEmpty(cliente) Then
' DTSPackageLog.WriteStringToLog "El cliente"&CStr(DTSSource("cliente_clave"))&" no esta en la dimension"
cliente = DTSLookups("get_id_cliente").Execute(-1)
End If

cantAnio = DTSLookups("cant_consultas_ao").Execute(cliente, servicio)
If (cantAnio>0) Then
REPETIDA = 1
NUEVA=0
Else
NUEVA = 1
REPETIDA=0
End If

'confirmada, asignada, nopresentada
If StrComp( DTSSource("COD_ESTADO"),DTSLookups("get_cit").Execute())=0 Then
ASIGNADA=1
ElseIf StrComp( DTSSource("COD_ESTADO"),DTSLookups("get_visit").Execute())=0 Then
CONFIRMADA=1
ElseIf StrComp( DTSSource("COD_ESTADO"),DTSLookups("get_np").Execute())=0 Then
NO_REALIZADA=1
End If

If IsNull(DTSSource("TIPO_CEX")) Then
ULTERIOR = 0
PRIMERA_VEZ=0
ElseIf CInt(DTSSource("TIPO_CEX"))=CInt(DTSLookups("get_id_prim_vez").Execute()) Then
PRIMERA_VEZ=1
ElseIf CInt(DTSSource("TIPO_CEX"))=CInt(DTSLookups("get_id_ult").Execute()) Then
ULTERIOR = 1
End If

If IsNull(DTSSource("TIEMPO_ESPERA")) Then
TIEMPO_ESPERA=-1
Else
TIEMPO_ESPERA=DTSSource("TIEMPO_ESPERA")
End If


If DTSLookups("existe_consulta_dia").Execute(cliente, profesional,servicio,fecha) = 0 Then
'NO HAY EN LA BASE UNA CONSULTA PARA ESE CLIENTE EN ESE SERVICIO Y FECHA
DTSDestination("CLIENTE_ID") = cliente
DTSDestination("PROFESIONAL_ID") = profesional

If (DTSSource("edad")<=0) Then
DTSDestination("GR_ETAREO_ID") = DTSLookups("get_id_gr_etareo").Execute(0,0)
Else
If IsEmpty(DTSLookups("get_id_gr_etareo").Execute(CInt(DTSSource("edad")),CInt(DTSSource("edad")))) Then
DTSPackageLog.WriteStringToLog "No sabe calcular para "&CStr(DTSSource("edad"))
Else
DTSDestination("GR_ETAREO_ID") = DTSLookups("get_id_gr_etareo").Execute(CInt(DTSSource("edad")),CInt(DTSSource("edad")))
End If
End If

If IsNull(DTSSource("ICD_COD")) Then
DTSDestination("DIAGNOS_ID") = DTSLookups("get_id_diagnos").Execute(-1)
Else
DTSDestination("DIAGNOS_ID") = DTSLookups("get_id_diagnos").Execute(DTSSource("ICD_COD"))
End If

DTSDestination("SERVICIOS_ID")= servicio
DTSDestination("FECHA_ID") = fecha

If IsNull(DTSSource("MOTIVO_CONS_CLAVE")) Then
DTSDestination("MOTIVO_CONS_ID")=DTSLookups("get_id_motivo_cons").Execute(1)
Else
DTSDestination("MOTIVO_CONS_ID") = DTSLookups("get_id_motivo_cons").Execute(DTSSource("MOTIVO_CONS_CLAVE"))
End If

If IsNull(DTSSource("PROFESIONAL_DERIV_CLAVE")) Then
DTSDestination("PROFESIONAL_DERIVADOR_ID")=DTSLookups("get_id_profesional").Execute(-1)
Else
DTSDestination("PROFESIONAL_DERIVADOR_ID")=DTSLookups("get_id_profesional").Execute(DTSSource("PROFESIONAL_DERIV_CLAVE"))
End If
DTSDestination("TIEMPO_ESPERA") = TIEMPO_ESPERA

DTSDestination("CONSULTAS_CONFIRMADAS") = CONFIRMADA
DTSDestination("CONSULTAS_ASIGNADAS") = ASIGNADA
DTSDestination("CONSULTAS_NO_REALIZADAS")=NO_REALIZADA
DTSDestination("CONSULTAS_PRIMERA_VEZ") = PRIMERA_VEZ
DTSDestination("CONSULTAS_ULTERIORES")=ULTERIOR
DTSDestination("CONSULTAS_NUEVAS")=NUEVA
DTSDestination("CONSULTAS_REPETIDAS")=REPETIDA
DTSDestination("CONSULTAS_PROGRAMADAS")=PROGRAMADA
DTSDestination("CONSULTAS_NO_PROGRAMADAS")=NO_PROGRAMADA
DTSDestination("cant_consult") = 1


msg="Inserto "&CStr(cliente)&" profesional "&CStr(profesional)&" fecha "&CStr(fecha)&" servicio "&CStr(servicio)

'MsgBox(msg)
Main = DTSTransformStat_OK
Else
'HAY EN LA BASE, SE ACTUALIZA
a= DTSLookups("actualiza_valores").Execute(TIEMPO_ESPERA, CONFIRMADA,ASIGNADA,NO_REALIZADA,PROGRAMADA,NO_PRO GRAMADA,PRIMERA_VEZ,ULTERIOR,NUEVA,REPETIDA,CLIENT E,PROFESIONAL,SERVICIO,FECHA)

msg="Actualizo "&CStr(cliente)&" profesional "&CStr(profesional)&" fecha "&CStr(fecha)&" servicio "&CStr(servicio)
'MsgBox(msg)
Main = DTSTransformStat_SkipRow
End If


End FunctionI have just looked through the code and it all looks fine.

I suspect your problem lies elsewhere. Perhaps in the data you are processing or in the target table you are going to.

I'm not sure what it could be though. Perhaps some sort of lock being generated on the table or database. I really don't know.

It's possible that your MDAC installation is corrupted (it can cause some very strange behaviour). If possible try installing MDAC 2.8 and see if that helps. It won't hurt that is for sure.

Sorry I couldn't be of more help.

Wednesday, February 15, 2012

DTS transaction problem

I created DTS package that has two connections “Source” and “Destination”, contains several “Execute SQL” tasks and several “Data Driven Query” tasks after them. For all tasks workflow properties are set to “Join transaction if present”, “Rollback transaction on failure” and “Fail package on step failure” except the last “Execute SQL” task that has also “Commit transaction on successful completion of this step” property set. The problem: when package started it successfully complete all “Execute SQL” tasks, but first DDQ task produce error “Transaction context in use by another session”. What can be a reason of such behavior? How to solve this problem? I need everything done in one transaction.

Thanks.

Andrey,
You're on the wrong forum. Try http://www.microsoft.com/technet/community/newsgroups/dgbrowser/en-us/default.mspx?dg=microsoft.public.sqlserver.dts

-Jamie