Friday, March 30, 2012
how to insert records from tiggers at batch update process
Pls help me........I suspect you wrote your trigger to work with one record at a time. I say this because of your comment of the trigger working for a one record update and the LAST record in a batch. Take a look at your trigger and ask yourself "What happens if I have three records to deal with in either the inserted OR deleted temp tables?"
Post your trigger and maybe we can offer some suggestions.|||Hi
This is the trigger i have used to split the records for various conditions from table1 and insert the splitted records into another table table2
The Problem i'm facing is if it is single update(if only one row is affected) the trigger is working fine,
but not for batch update.
if you are unable to follow this trigger pls give your own batch update example, we will try to implement that.
pls help me.
CREATE trigger udt_Break_Split
ON Hours_tmp
/*
this trigger is used to do the break split in the table hours_tmp
and insert the records into the table selnmuamid
*/
AFTER UPDATE
AS
Declare @.Id int
Declare @.Res_id nvarchar(8)
Declare @.DTime smalldatetime
Declare @.StartTime char(5)
Declare @.EndTime char(5)
Declare @.Pauze char(5)
Declare @.Hourworked nvarchar(5)
Declare @.Status char(1)
--Declare @.PPayroll bit
Declare @.Project nvarchar(10)
Declare @.Naam char(50)
Declare @.Type char(5)
Declare @.Hryear nvarchar(4)
Declare @.Totmin char(5)
Declare @.Endtimebr char(5)
Declare @.Stime char(5)
Declare @.Start char(5)
Declare @.Processed char(1)
Declare @.del_DTime smalldatetime
Declare @.del_StartTime char(5)
Declare @.del_EndTime char(5)
Declare @.Del_id int
Declare @.Totrows int
--update hours_tmp set hours_tmp.processed_payroll =1 from hours_tmp , inserted where hours_tmp.id = inserted.id
Select @.Id=Id,
@.Res_id=Res_id,
@.DTime=[Datetime],
@.Start=Starttime,
@.EndTime=Endtime,
@.Pauze=Pauze,
@.Hourworked=Hoursworked,
@.Status=Status,
@.Project=Project,
@.Naam=Naam,
@.Type=Type,
@.Hryear=Hryear,
@.Processed=Processed
From inserted -- i ,Hours_tmp h where i.[Id] = h.[id]
Select @.del_DTime=[DateTime],
@.del_Starttime=Starttime,
@.del_endTime=Endtime ,
@.del_id=id
From Deleted
Delete From Selnmuamid
Where Res_id=@.Res_id
and Datetime=@.del_DTime
and Starttime >=@.del_starttime
and Endtime <=@.del_endtime
-- This is To Get total hours (hourworked column in the table ) in minutes
Select @.Totmin=Sum(Convert(Integer,(Left(@.hourworked,Char index('.',@.hourworked)-1) *
60)) +Convert(Integer,(Right(@.hourworked,Len(@.hourworke d) -
Charindex('.',@.hourworked))))),@.Endtimebr=Sum(Conv ert(Integer,(Left(@.Endtime,Charindex(':',@.Endtime) -1) *
60)) + Convert(Integer,(Right(@.Endtime,Len(@.Endtime) -
Charindex(':',@.Endtime))))),@.Stime=Sum(Convert(Int eger,(Left(@.Start,Charindex(':',@.Start)-1) * 60)) +
Convert(Integer,(Right(@.Start,Len(@.Start) - Charindex(':',@.Start)))))
--Values Passed as Parameter to Stored procedure Break_Split
Exec Break_Split @.Id,@.Res_id,@.DTime,@.Start,@.EndTime,@.Pauze,
@.Hourworked,@.Status,@.Project,@.Naam,@.Type,
@.Hryear,@.Totmin,@.Endtimebr,@.STime,@.Processed|||basically I just wrapped your code in a while loop to step through each record in the inserted temp table. Then I moveded the delete Selnmuamid to the end.
This has NOT been tested!
Code:
------------------------------
CREATE trigger udt_Break_Split
ON Hours_tmp
/*
this trigger is used to do the break split in the table hours_tmp
and insert the records into the table selnmuamid
*/
AFTER UPDATE
AS
-- ----------------
-- One Declare is more efficient than multipule declares
-- ----------------
Declare @.Id int
, @.Res_id nvarchar(8)
, @.DTime smalldatetime
, @.StartTime char(5)
, @.EndTime char(5)
, @.Pauze char(5)
, @.Hourworked nvarchar(5)
, @.Status char(1)
-- , @.PPayroll bit
, @.Project nvarchar(10)
, @.Naam char(50)
, @.Type char(5)
, @.Hryear nvarchar(4)
, @.Totmin char(5)
, @.Endtimebr char(5)
, @.Stime char(5)
, @.Start char(5)
, @.Processed char(1)
, @.del_DTime smalldatetime
, @.del_StartTime char(5)
, @.del_EndTime char(5)
, @.Del_id int
, @.Totrows int
--update hours_tmp set hours_tmp.processed_payroll =1 from hours_tmp , inserted where hours_tmp.id = inserted.id
select @.Id = min(ID) from inserted
while (@.Id is not null) begin
Select @.Res_id = Res_id
, @.DTime = [Datetime]
, @.Start = Starttime
, @.EndTime = Endtime
, @.Pauze = Pauze
, @.Hourworked = Hoursworked
, @.Status = Status
, @.Project = Project
, @.Naam = Naam
, @.Type = Type
, @.Hryear = Hryear
, @.Processed = Processed
-- ---------------------------------------------------
-- Hoursworked, Endtime and StartTime need to be converted to minutes
-- ---------------------------------------------------
, @.Totmin = Convert(Integer,(Left(Hoursworked,Charindex('.',Ho ursworked)-1) * 60)) + Convert(Integer,(Right(Hoursworked,Len(Hoursworked ) - Charindex('. ',Hoursworked))))
, @.Endtimebr = Convert(Integer,(Left(Endtime, Charindex(':',Endtime)-1) * 60)) + Convert(Integer,(Right(Endtime, Len(Endtime) - Charindex(':',Endtime))))
, @.Stime = Convert(Integer,(Left(Starttime, Charindex(':',Starttime)-1) * 60)) + Convert(Integer,(Right(Starttime, Len(Starttime) - Charindex(':',Starttime)))))
From inserted i
where id = @.id
-- This is To Get total hours (hourworked column in the table ) in minutes
/*
Select @.Totmin = Sum(Convert(Integer,(Left(@.hourworked,Charindex('. ',@.hourworked)-1) * 60)) +
Convert(Integer,(Right(@.hourworked,Len(@.hourworked ) - Charindex('. ',@.hourworked)))))
, @.Endtimebr = Sum(Convert(Integer,(Left(@.Endtime,Charindex(':',@. Endtime)-1) * 60)) +
Convert(Integer,(Right(@.Endtime,Len(@.Endtime) - Charindex(':',@.Endtime)))))
, @.Stime = Sum(Convert(Integer,(Left(@.Start,Charindex(':',@.St art)-1) * 60)) +
Convert(Integer,(Right(@.Start,Len(@.Start) - Charindex(':',@.Start)))))
*/
-- Values Passed as Parameter to Stored procedure Break_Split
Exec Break_Split @.Id,@.Res_id,@.DTime,@.Start,@.EndTime,@.Pauze,@.Hourwor ked,@.Status,@.Project,@.Naam,@.Type,@.Hryear,@.Totmin,@. Endtimebr,@.STime,@.Processed
select @.Id = min(ID) from inserted where id > @.id
end
-- -------------------
-- The deleted temp table can be joined to the Selnmuamid table
-- to deleted the unwanted records. If you need the ID from the
-- inserted table then join the inserted table with the
-- deleted table and then join the Selnmuamid table.
-- This is a good example of how you can ditch the row-at-a-time
-- mentality and start using set theory for processing records.
-- -------------------
delete
from Selnmuamid s
join deleted d on s.Res_id = d.Res_id
where [s.Datetime] = d.del_DTime
and s.Starttime >= d.del_starttime
and s.Endtime <= d.del_endtime
/*
Select @.del_DTime = [DateTime]
, @.del_Starttime = Starttime
, @.del_endTime = Endtime
, @.del_id = [id]
From Deleted
where Id = @.Id
Delete
From Selnmuamid
Where Res_id = @.Res_id
and [Datetime] = @.del_DTime
and Starttime >= @.del_starttime
and Endtime <= @.del_endtime
*/
------------------------------
How to Insert or Update Records from Source to Destination using Oracle 8i DB
Hi !
I need help for SSIS Pacakge. using condtional Split How to insert One records with Multiple time depending on Source column value .Is there possible to wrtie the condition in Conditional split.
For Exmaple :
Source Table Name : tbl_source
following Column Name: col_Name1,Col_Name2,Col_Name3, col_Id,Col_Descrip
table contain only one records:GRD1,SRD1,FRD1,100,Product
I want Insert the Destiantion table the Follwing Condition. using Conditional Split.
1)Cond1 (!(ISNULL(GRD1))
2)Cond2 !(ISNULL(SRD1))
3)Cond3 !(ISNULL(FRD1))
I need the Following output
Destination Table Name : tbl _Dest(for One record in source table i need following records in destination)
Coulmn Name , Column Value , ID
Row 1 GRD GRD1 100
Row 2 SRD SRD1 100
Row 3 FRD FRD1 100
How to achieve this result. can u anyone help me.using Conditional split iam getting only first condition Result.
Thanks & regards
M.Jeyakumar
Hi,
You can not do it thru Conditional split. Use script component to do this.
|||Have you try using the Multicast task?|||Hi , thanks for your repley. can you give samples control flow for this one .
Thanks & regards
Jeyakumar
|||Maybe something like this...
Multicast Task A -> Conditional Split Task 1 -> Derived Column Task 1 -> Destination 1
Multicast Task A -> Conditional Split Task 2 -> Derived Column Task 2 -> Destination 2
Multicast Task A -> Conditional Split Task 3 -> Derived Column Task 3 -> Destination 3
One Multicast Task that split into 3 transformations.
|||Hi HienPhilly,
Thank you for your kind of Help. Now its working fine. i designed the above dataflow diagram.now its working fine.i need another doubt in using Lookup in SSIS.
There are two Tables .
1) Product_ tbl
2) Master_Prod_tbl
Using Lookup i want all the Product_tbl column values(i.e Source table) only if Matching the Poduct_tbl_ProductID=Master_Prod_tbl
How to achieve this one ?
the following data flow i am using
1) Product_tbl -> Lookup-->Dstination table
in the Lookup the follwing sql query i wrote:
Select p.GDR,p.CUSIP,p.ISING,p.SEDUL FROM Product_tbl p,Master_Prod_tbl m
WHERE p.CODE=m.CODE
but it didn't work? pls give me your suggestion.
Thanks & Regards
Jeyakumar.M
|||I don't think you are using it correctly. Under the Reference Table tab, you should have your master_prod_tbl table. Under the Column tab is where you map your lookup column. And if you only want the matched records, you have to Configure Error Output...
|||i think you mean "transformation" instead of "task".|||Hienphilly wrote:
Maybe something like this...
Multicast Task A -> Conditional Split Task 1 -> Derived Column Task 1 -> Destination 1
Multicast Task A -> Conditional Split Task 2 -> Derived Column Task 2 -> Destination 2
Multicast Task A -> Conditional Split Task 3 -> Derived Column Task 3 -> Destination 3
One Multicast Task that split into 3 transformations.
Hi Very thankful for your Help. The Problem was i am not configure the Error OutPut. Now its working fine.
I need another Help using Oracle 8i Database
i have two sql statement :
1) Source Sql Statement(select)
2) Update or Insert
How to achive in SSIS Package .is it possible to use Sql Command in SCD Transfermation ? pls give me ur suggestion.
Thanks & Regards,
M.Jeyakumar
|||Jkumar wrote:
i have two sql statement :
1) Source Sql Statement(select)
2) Update or Insert
How to achive in SSIS Package .is it possible to use Sql Command in SCD Transfermation ? pls give me ur suggestion.
Sorry, I'm not really understanding. Do you want to update some data using data in the SSIS pipeline? If so, use the OLE DB Command component.
-Jamie
|||Hi ,
Previously i was tried using Sql Server DB .Now i am using Oracle 8i DB.
Using BI How to INSERT Or UPdate Records from Source to Destination.
Condition.:
1) The source records are New Records t hen The Destination should b e INSERTED
2) Already is there then it should be UPDATED
.How to Achieve this using ORAcle 8i. Whatever u already gave the sloution using SCD Transformation .its working in SQL DB.But now ia musing Oracle 8i it throwing Error.
can i use the Sql command for Insert or Update with Where Condition.
Thanks & regards,
M.Jeyakumar
|||Jkumar wrote:
Hi ,
Previously i was tried using Sql Server DB .Now i am using Oracle 8i DB.
Using BI How to INSERT Or UPdate Records from Source to Destination.
Condition.:
1) The source records are New Records t hen The Destination should b e INSERTED
2) Already is there then it should be UPDATED
.How to Achieve this using ORAcle 8i. Whatever u already gave the sloution using SCD Transformation .its working in SQL DB.But now ia musing Oracle 8i it throwing Error.
can i use the Sql command for Insert or Update with Where Condition.
Thanks & regards,
M.Jeyakumar
I presume by "SQL Command" you mean "OLE DB Command". The answer is yes, you can use it. And it SHOULD work against Oracle.
-Jamie
How to Insert One Row with Multiple time depding on Source Column value in SSIS Pacakge
Hi !
I need help for SSIS Pacakge. using condtional Split How to insert One records with Multiple time depending on Source column value .Is there possible to wrtie the condition in Conditional split.
For Exmaple :
Source Table Name : tbl_source
following Column Name: col_Name1,Col_Name2,Col_Name3, col_Id,Col_Descrip
table contain only one records:GRD1,SRD1,FRD1,100,Product
I want Insert the Destiantion table the Follwing Condition. using Conditional Split.
1)Cond1 (!(ISNULL(GRD1))
2)Cond2 !(ISNULL(SRD1))
3)Cond3 !(ISNULL(FRD1))
I need the Following output
Destination Table Name : tbl _Dest(for One record in source table i need following records in destination)
Coulmn Name , Column Value , ID
Row 1 GRD GRD1 100
Row 2 SRD SRD1 100
Row 3 FRD FRD1 100
How to achieve this result. can u anyone help me.using Conditional split iam getting only first condition Result.
Thanks & regards
M.Jeyakumar
Hi,
You can not do it thru Conditional split. Use script component to do this.
|||Have you try using the Multicast task?|||Hi , thanks for your repley. can you give samples control flow for this one .
Thanks & regards
Jeyakumar
|||Maybe something like this...
Multicast Task A -> Conditional Split Task 1 -> Derived Column Task 1 -> Destination 1
Multicast Task A -> Conditional Split Task 2 -> Derived Column Task 2 -> Destination 2
Multicast Task A -> Conditional Split Task 3 -> Derived Column Task 3 -> Destination 3
One Multicast Task that split into 3 transformations.
|||Hi HienPhilly,
Thank you for your kind of Help. Now its working fine. i designed the above dataflow diagram.now its working fine.i need another doubt in using Lookup in SSIS.
There are two Tables .
1) Product_ tbl
2) Master_Prod_tbl
Using Lookup i want all the Product_tbl column values(i.e Source table) only if Matching the Poduct_tbl_ProductID=Master_Prod_tbl
How to achieve this one ?
the following data flow i am using
1) Product_tbl -> Lookup-->Dstination table
in the Lookup the follwing sql query i wrote:
Select p.GDR,p.CUSIP,p.ISING,p.SEDUL FROM Product_tbl p,Master_Prod_tbl m
WHERE p.CODE=m.CODE
but it didn't work? pls give me your suggestion.
Thanks & Regards
Jeyakumar.M
|||I don't think you are using it correctly. Under the Reference Table tab, you should have your master_prod_tbl table. Under the Column tab is where you map your lookup column. And if you only want the matched records, you have to Configure Error Output...
|||i think you mean "transformation" instead of "task".|||Hienphilly wrote:
Maybe something like this...
Multicast Task A -> Conditional Split Task 1 -> Derived Column Task 1 -> Destination 1
Multicast Task A -> Conditional Split Task 2 -> Derived Column Task 2 -> Destination 2
Multicast Task A -> Conditional Split Task 3 -> Derived Column Task 3 -> Destination 3
One Multicast Task that split into 3 transformations.
Hi Very thankful for your Help. The Problem was i am not configure the Error OutPut. Now its working fine.
I need another Help using Oracle 8i Database
i have two sql statement :
1) Source Sql Statement(select)
2) Update or Insert
How to achive in SSIS Package .is it possible to use Sql Command in SCD Transfermation ? pls give me ur suggestion.
Thanks & Regards,
M.Jeyakumar
|||Jkumar wrote:
i have two sql statement :
1) Source Sql Statement(select)
2) Update or Insert
How to achive in SSIS Package .is it possible to use Sql Command in SCD Transfermation ? pls give me ur suggestion.
Sorry, I'm not really understanding. Do you want to update some data using data in the SSIS pipeline? If so, use the OLE DB Command component.
-Jamie
|||Hi ,
Previously i was tried using Sql Server DB .Now i am using Oracle 8i DB.
Using BI How to INSERT Or UPdate Records from Source to Destination.
Condition.:
1) The source records are New Records t hen The Destination should b e INSERTED
2) Already is there then it should be UPDATED
.How to Achieve this using ORAcle 8i. Whatever u already gave the sloution using SCD Transformation .its working in SQL DB.But now ia musing Oracle 8i it throwing Error.
can i use the Sql command for Insert or Update with Where Condition.
Thanks & regards,
M.Jeyakumar
|||Jkumar wrote:
Hi ,
Previously i was tried using Sql Server DB .Now i am using Oracle 8i DB.
Using BI How to INSERT Or UPdate Records from Source to Destination.
Condition.:
1) The source records are New Records t hen The Destination should b e INSERTED
2) Already is there then it should be UPDATED
.How to Achieve this using ORAcle 8i. Whatever u already gave the sloution using SCD Transformation .its working in SQL DB.But now ia musing Oracle 8i it throwing Error.
can i use the Sql command for Insert or Update with Where Condition.
Thanks & regards,
M.Jeyakumar
I presume by "SQL Command" you mean "OLE DB Command". The answer is yes, you can use it. And it SHOULD work against Oracle.
-Jamie
Wednesday, March 7, 2012
How to implement split and merge?
I need to implement following flow:
[Source] - > [Split]
- [IF TRUE] -> [DO SOMETHING] - [OUTPUT TO C]
- [IF FALSE] -> [DO SOMETHING ELSE] - [OUTPUT TO C]
The issue is to come back to the same destination after conditional split.
In other words, is there something opposite to "Multicast"?
I looked at Union and Merge - but it looks like it's not for this kind of things.
Thanks.
That sounds like a UnionAll to me...Why do you think UnionAll is not for this kind of thing? Do the two output (true output and the false output) downstreams change the column metadata in different ways?
thanks
wenyang
|||I may not be understaning Union All well. Doesn't it require bith streams to have some data in it? To map fields from both streams?
In my scenario - only one stream has data in the buffer at the same time.
|||There is no requirement for both inputs into a UNION ALL component to both have data. It will work perfectly well if no rows at all are passed through it - which is of course true for all components.
-Jamie
|||This worked! Thanks!