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

Tuesday, March 27, 2012

CONCAT in Execute SQL Task

I am curious to know if there is a way to suppress or temporarily store event errors until the final one, then take all those errors and write to db field?

I have a package that uses an event error to store msgs into a field. But, I end up getting several errors that will overwrite my db field each time. Only about two out of 10 are relevent to my problem...

I just need to know if there is a way to suppress the number of event errors that come over , or concat them into one event, per event that occurs? Right now when I hit an error, I end up getting 10 error messages that follow, so my OnError event gets triggered 10 times..

Jason

One way to handle this may be to count the errors using a script in your event handler. Update a variable until you reach the last error you wish to handle, then enable the behaviour you wish to execute.

Donald Farmer

Group Program Manager

SQL Server Integration Services

|||Thanks Donald, how do I determine when the final error occurs in a failure?

So, let's say I have an object that fails, I get 5 onerror event called msgs, how do I know that 5 (or whatever number) is my last error msg for the failure?|||

Is it possible to concat in a Execute SQL Task - T-SQL statement? I tried to do this:

UPDATE ETL_Transactions SET LogDetails = LogDetails + ?, TransactionStatus = 'Failed' WHERE TransactionID = ?

where LogDetails is the field I want to concat with another parameter. However, this doesn't work! IS it supposed to, or am I missing something?

|||

scoobyjw wrote:

Is it possible to concat in a Execute SQL Task - T-SQL statement? I tried to do this:

UPDATE ETL_Transactions SET LogDetails = LogDetails + ?, TransactionStatus = 'Failed' WHERE TransactionID = ?

where LogDetails is the field I want to concat with another parameter. However, this doesn't work! IS it supposed to, or am I missing something?

Jason,
Why not try building the SQL statement using a property expression on the SQLStatementSource property?

-Jamie|||The problem is that when this query runs [UPDATE ETL_Transactions SET LogDetails = LogDetails + ?, TransactionStatus = 'Failed' WHERE TransactionID = ?]

and LogDetails tries to concat (LogDetails + ?), it errors out because LogDetails has a null value (as it should the first time around)... It doesn't like setting null values in the query. Is there a way to say:

if Not Null(SET LogDetails = LogDetails + ?)
else LogDetails = ?

? Sorry about the pseudo code, I am not an expert at SQL.|||

scoobyjw wrote:

The problem is that when this query runs [UPDATE ETL_Transactions SET LogDetails = LogDetails + ?, TransactionStatus = 'Failed' WHERE TransactionID = ?]

and LogDetails tries to concat (LogDetails + ?), it errors out because LogDetails has a null value (as it should the first time around)... It doesn't like setting null values in the query. Is there a way to say:

if Not Null(SET LogDetails = LogDetails + ?)
else LogDetails = ?

? Sorry about the pseudo code, I am not an expert at SQL.

Yeah, try this:
[UPDATE ETL_Transactions SET LogDetails = COALESCE(LogDetails, '') + ?, TransactionStatus = 'Failed' WHERE TransactionID = ?]

I really think you should look at using a property expression tho Smile

-Jamie

Computing Dates

I'm soliciting any suggestions from the readers of the group on how
best to tackle this task. I need to determine if trouble tickets
opened get closed within 4 hours. Yes, I already know about
datediff(hh, date1, date2, but it's not that simple. The thing I'm
struggle with is that I need to take inaccount business hours (8:00am
to 4:00pm). If date1 is 10/27/05 2:00pm then the 4 hour window ends at
10/28/05 10:00am. Any suggestions are much appreciated.Try,
if (convert(char(8), @.sd, 112) = convert(char(8), @.ed, 112) and datediff(hh,
@.sd, @.ed) <= 4) or (convert(char(8), @.sd, 112) < convert(char(8), @.ed, 112)
and (datediff(hh, @.sd, @.ed) - 8) <= 4) print 'may be in 4 hours'
else
'more than 4 hours'
AMB
"BobD" wrote:

> I'm soliciting any suggestions from the readers of the group on how
> best to tackle this task. I need to determine if trouble tickets
> opened get closed within 4 hours. Yes, I already know about
> datediff(hh, date1, date2, but it's not that simple. The thing I'm
> struggle with is that I need to take inaccount business hours (8:00am
> to 4:00pm). If date1 is 10/27/05 2:00pm then the 4 hour window ends at
> 10/28/05 10:00am. Any suggestions are much appreciated.
>|||Correction:
if (convert(char(8), @.sd, 112) = convert(char(8), @.ed, 112) and datediff(hh,
@.sd, @.ed) <= 4) or (convert(char(8), @.sd, 112) < convert(char(8), @.ed, 112)
and (datediff(hh, @.sd, @.ed) - 20) <= 4)
print 'may be in 4 hours'
else
'more than 4 hours'
go
AMB
"Alejandro Mesa" wrote:
> Try,
> if (convert(char(8), @.sd, 112) = convert(char(8), @.ed, 112) and datediff(h
h,
> @.sd, @.ed) <= 4) or (convert(char(8), @.sd, 112) < convert(char(8), @.ed, 112
)
> and (datediff(hh, @.sd, @.ed) - 8) <= 4) print 'may be in 4 hours'
> else
> 'more than 4 hours'
>
> AMB
> "BobD" wrote:
>|||Correction: (sorry guys)
if (convert(char(8), @.sd, 112) = convert(char(8), @.ed, 112) and datediff(hh,
@.sd, @.ed) <= 4) or (convert(char(8), @.sd, 112) < convert(char(8), @.ed, 112)
and (datediff(hh, @.sd, @.ed) - 16) <= 4)
print 'may be in 4 hours'
else
'more than 4 hours'
go
AMB
"Alejandro Mesa" wrote:
> Correction:
> if (convert(char(8), @.sd, 112) = convert(char(8), @.ed, 112) and datediff(h
h,
> @.sd, @.ed) <= 4) or (convert(char(8), @.sd, 112) < convert(char(8), @.ed, 112
)
> and (datediff(hh, @.sd, @.ed) - 20) <= 4)
> print 'may be in 4 hours'
> else
> 'more than 4 hours'
> go
>
> AMB
> "Alejandro Mesa" wrote:
>|||Bob,
Try this:
SELECT
CASE WHEN cast(convert(varchar(12),date1,114) as datetime) < '08:00'
THEN dateadd(day,datediff(day,0,date1),'12:00
')
WHEN cast(convert(varchar(12),date1,114) as datetime) < '12:00'
THEN dateadd(hour,4,date1)
ELSE dateadd(hour,20,date1) END
FROM yourTable
Steve Kass
Drew University
BobD wrote:

>I'm soliciting any suggestions from the readers of the group on how
>best to tackle this task. I need to determine if trouble tickets
>opened get closed within 4 hours. Yes, I already know about
>datediff(hh, date1, date2, but it's not that simple. The thing I'm
>struggle with is that I need to take inaccount business hours (8:00am
>to 4:00pm). If date1 is 10/27/05 2:00pm then the 4 hour window ends at
>10/28/05 10:00am. Any suggestions are much appreciated.
>
>|||Bod
try this
SELECT CASE WHEN DATE1 = DATE2 THEN DATEDIFF(HOUR, DATE1,DATE2) ELSE
DATEDIFF(HOUR, DATE1,(DATEADD(HOUR,-16,DATE2)))
--
Regards
R.D
--Knowledge gets doubled when shared
"BobD" wrote:

> I'm soliciting any suggestions from the readers of the group on how
> best to tackle this task. I need to determine if trouble tickets
> opened get closed within 4 hours. Yes, I already know about
> datediff(hh, date1, date2, but it's not that simple. The thing I'm
> struggle with is that I need to take inaccount business hours (8:00am
> to 4:00pm). If date1 is 10/27/05 2:00pm then the 4 hour window ends at
> 10/28/05 10:00am. Any suggestions are much appreciated.
>

Tuesday, March 20, 2012

Compressed Drive

I have been given the task of fixing a design problem. We have a 2 GB database (and growing) on a compressed drive. If I decompress the drive what impact if any will there be on the Database or data?This should increase your performance. As far as database concerns, you should not see any issues. However, backup or copy the database to another drive before you proceed. Also, run dbcc checkdb to check the database for any issues - run this before and after the operation. And make sure that you have enough disk space for the decompressed version of the database.

Sunday, March 11, 2012

Complicated Task Please Help

Hi All,
I have a requirment to pull a query that would result in something like the
following:
[Service Line] | [POCount] | WEnd-04-02-2005 | WEnd-04-9-2005 |
WEnd-04-016-2005 | WEnd-04-26-2005
MNS 15 3
2 10
etc...
I create a temp table and dump the data into it and find the Wending by
using a function.
My problme is that I can't get it to group like indicated above.
Below is my entire code, excluding the Function.
Please Help... I'm desperate :)
John.
CREATE PROCEDURE dbo.usp_RPT_OPW_FLASH
@.startdate SmallDateTime,
@.enddate SmallDateTime
AS
SET NOCOUNT ON
BEGIN TRANSACTION
---
--Create Temporary Table To Hold the data
---
Create Table #tmpOPW_FLASH (
[Service Line] VarChar(50),
[Total Of PONumber]INT,
RC DateTime,
RS DateTime,
CycleTime Decimal(18,2),
WEnding DateTime
)
---
--Insert Data into temporary table for DATE_ORDERED (Issued)
---
INSERT INTO #tmpOPW_FLASH([Service Line], [Total Of PONumber], RC, RS)
SELECT T1.DataSource AS [Service Line], COUNT(T1.PoNumber) AS [Total Of
PONumber],
T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME) AS RC,
T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME) AS RS
FROM OPW T1 INNER JOIN
(SELECT PoNumber
FROM OPW
GROUP BY PoNumber
HAVING COUNT(*) > 1) T2 ON T1.PoNumber = T2.PoNumber
WHERE (T1.ReqSubmitDate BETWEEN @.startdate AND @.enddate)
GROUP BY T1.DataSource, T1.REQCreateDate + CAST(T1.REQCreateTime AS
DATETIME), T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME)
---
--UPDATE CycleTime and WEnding Column
---
UPDATE #tmpOPW_FLASH
SET CycleTime = DateDiff(hh, RC, RS),
WEnding = DBO.usf_WEnding(RS)
----
SELECT [Service Line], [Total Of PONumber], WEnding
FROM #tmpOPW_FLASH
GROUP BY [Service Line], [Total Of PONumber], WEnding
DROP TABLE #tmpOPW_FLASH
COMMIT TRANSACTIONI think that you wont need your Temp table although i cant understand your
intention, but these update can be done in an inline statement, because you
are only calling a function to do this. Please post some DDL and smaple data
which can be read a bit better then the pasting of your last post, and well
fix it together :-)
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"John Rugo" <jrugo@.patmedia.net> schrieb im Newsbeitrag
news:uAbrsS1SFHA.3544@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> I have a requirment to pull a query that would result in something like
> the following:
> [Service Line] | [POCount] | WEnd-04-02-2005 | WEnd-04-9-2005 |
> WEnd-04-016-2005 | WEnd-04-26-2005
> MNS 15 3 2
> 10
> etc...
> I create a temp table and dump the data into it and find the Wending by
> using a function.
> My problme is that I can't get it to group like indicated above.
> Below is my entire code, excluding the Function.
> Please Help... I'm desperate :)
> John.
>
> CREATE PROCEDURE dbo.usp_RPT_OPW_FLASH
> @.startdate SmallDateTime,
> @.enddate SmallDateTime
> AS
> SET NOCOUNT ON
> BEGIN TRANSACTION
> ---
> --Create Temporary Table To Hold the data
> ---
> Create Table #tmpOPW_FLASH (
> [Service Line] VarChar(50),
> [Total Of PONumber]INT,
> RC DateTime,
> RS DateTime,
> CycleTime Decimal(18,2),
> WEnding DateTime
> )
> ---
> --Insert Data into temporary table for DATE_ORDERED (Issued)
> ---
> INSERT INTO #tmpOPW_FLASH([Service Line], [Total Of PONumber], RC, RS)
> SELECT T1.DataSource AS [Service Line], COUNT(T1.PoNumber) AS [Total Of
> PONumber],
> T1.REQCreateDate + CAST(T1.REQCreateTime AS DATETIME) AS RC,
> T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME) AS RS
> FROM OPW T1 INNER JOIN
> (SELECT PoNumber
> FROM OPW
> GROUP BY PoNumber
> HAVING COUNT(*) > 1) T2 ON T1.PoNumber = T2.PoNumber
> WHERE (T1.ReqSubmitDate BETWEEN @.startdate AND @.enddate)
> GROUP BY T1.DataSource, T1.REQCreateDate + CAST(T1.REQCreateTime AS
> DATETIME), T1.ReqSubmitDate + CAST(T1.ReqSubmitTime AS DATETIME)
> ---
> --UPDATE CycleTime and WEnding Column
> ---
> UPDATE #tmpOPW_FLASH
> SET CycleTime = DateDiff(hh, RC, RS),
> WEnding = DBO.usf_WEnding(RS)
> ----
> SELECT [Service Line], [Total Of PONumber], WEnding
> FROM #tmpOPW_FLASH
> GROUP BY [Service Line], [Total Of PONumber], WEnding
> DROP TABLE #tmpOPW_FLASH
> COMMIT TRANSACTION
>|||Your approach is too procedural. Create a table of reporting periods:
CREATE TABLE ReportPeriods
(period_name CHAR (20) NOT NULL PRIMARY KEY,
period_start_date DATETIME NOT NULL,
period_end_date DATETIME NOT NULL,
CHECK (period_start_date < period_end_date));
Then write something like:
SELECT service_line, po_cnt,
CASE WHEN OPW.some_date BETWEEN R1.period_start_date and
period_end_date
AND R1.period_name = ''WEnd-2005-04-02'
THEN 1 ELSE 0 END AS wend-2005-04-02,
etc.
FROM ReportPeriods AS R1, OPW
WHERE ... ;
In short, think in terms of joins and not computations.
You are also making the classic Newbie error of trying to format the
data and the column headers in the backend. The whole point of a
tiered architecture is that you do this only in the front end.
Also, please post DDL, so that people do not have to guess what the
keys, constraints, Declarative Referential Integrity, datatypes, etc.
in your schema are. Sample data is also a good idea, along with clear
specifications.|||/* general this is the type of data and structure I am working with.
I need to show the data as indicated before below:
Basically I did this on the Applications Front end and sent in a Dynamic SQL
string. I know there must be a way to do this via a procedure; I'm just
learning the more advanced stuff now.
One of my current delemas is getting the WEnd items to be grouped
columniarly as show below.
*/
CREATE TABLE OPW (
DataSource VarChar(50),
PoNumber VarChar(22),
ReqCreateDate datetime
ReqCreateTime varchar(10),
ReqSubmitDate datetime
ReqSubmitTime varchar(10),
NamePrep varchar(240))
INSERT INTO OPW ('MNS', PW02939, '04/01/2005', '11:39:58', '04/04/2005',
'12:30:00', 'JOHN')
INSERT INTO OPW ('MNS', PW02939, '04/01/2005', '11:39:58', '04/04/2005',
'12:30:00', 'BILL')
INSERT INTO OPW ('MNS', PW02937, '04/03/2005', '11:39:58', '04/07/2005',
'12:30:00', 'JOHN')
INSERT INTO OPW ('MNS', PW02934, '04/20/2005', '11:39:58', '04/23/2005',
'12:30:00', 'BOB')
INSERT INTO OPW ('MNS', PW02937, '04/03/2005', '11:39:58', '04/07/2005',
'12:30:00', 'JOHN')
INSERT INTO OPW ('MNS', PW02933, '04/17/2005', '11:39:58', '04/20/2005',
'12:30:00', 'JOHN')
/*
Service Line PO Created By Total Of PONumber 04/02/2005 04/09/2005
04/16/2005 04/23/2005 04/30/2005
EVPN MURPHY, ANTOINETTE J 4 4
MNS ADELER, LISA 13 11 2
MNS ARAGON, JENNIFER 59 35 24
MNS BERIG, CARI 22 12 10
MNS KIRBY, DANIEL 101 76 25
MNS KRENKEL, LISA R 60 60
MNS LEONARDELLI, JOHN MICHAEL 143 40 103
MNS MADSEN, SHANE 24 14 10
MNS MURPHY, ANTOINETTE J 3 3
MNS PYELL, CLAUDETTE 11 11
MNS SCARBOROUGH, MERNA 80 10 70
MNS WHALEY, LEE 6 6
*/
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:OwD31a1SFHA.580@.TK2MSFTNGP15.phx.gbl...
>I think that you wont need your Temp table although i cant understand
>your intention, but these update can be done in an inline statement,
>because you are only calling a function to do this. Please post some DDL
>and smaple data which can be read a bit better then the pasting of your
>last post, and well fix it together :-)
> HTH, Jens Suessmeyer.
> --
> http://www.sqlserver2005.de
> --
> "John Rugo" <jrugo@.patmedia.net> schrieb im Newsbeitrag
> news:uAbrsS1SFHA.3544@.TK2MSFTNGP10.phx.gbl...
>|||Sorry i read for about 10 minutes you ddl and output (whch is formatted in a
strange way) and even now i dont know what you are going to do. I am
willing to help you but i cant understand your question. :-(
If this oist will last too long and i loose track of it, jst write me an
email to see wheter we can check it off ngposting and post the results back.
Jens Suessmeyer.
"John Rugo" <jrugo@.patmedia.net> schrieb im Newsbeitrag
news:%23RbaS61SFHA.900@.TK2MSFTNGP10.phx.gbl...
> /* general this is the type of data and structure I am working with.
> I need to show the data as indicated before below:
> Basically I did this on the Applications Front end and sent in a Dynamic
> SQL string. I know there must be a way to do this via a procedure; I'm
> just learning the more advanced stuff now.
> One of my current delemas is getting the WEnd items to be grouped
> columniarly as show below.
> */
> CREATE TABLE OPW (
> DataSource VarChar(50),
> PoNumber VarChar(22),
> ReqCreateDate datetime
> ReqCreateTime varchar(10),
> ReqSubmitDate datetime
> ReqSubmitTime varchar(10),
> NamePrep varchar(240))
> INSERT INTO OPW ('MNS', PW02939, '04/01/2005', '11:39:58', '04/04/2005',
> '12:30:00', 'JOHN')
> INSERT INTO OPW ('MNS', PW02939, '04/01/2005', '11:39:58', '04/04/2005',
> '12:30:00', 'BILL')
> INSERT INTO OPW ('MNS', PW02937, '04/03/2005', '11:39:58', '04/07/2005',
> '12:30:00', 'JOHN')
> INSERT INTO OPW ('MNS', PW02934, '04/20/2005', '11:39:58', '04/23/2005',
> '12:30:00', 'BOB')
> INSERT INTO OPW ('MNS', PW02937, '04/03/2005', '11:39:58', '04/07/2005',
> '12:30:00', 'JOHN')
> INSERT INTO OPW ('MNS', PW02933, '04/17/2005', '11:39:58', '04/20/2005',
> '12:30:00', 'JOHN')
>
> /*
> Service Line PO Created By Total Of PONumber 04/02/2005 04/09/2005
> 04/16/2005 04/23/2005 04/30/2005
> EVPN MURPHY, ANTOINETTE J 4 4
> MNS ADELER, LISA 13 11 2
> MNS ARAGON, JENNIFER 59 35 24
> MNS BERIG, CARI 22 12 10
> MNS KIRBY, DANIEL 101 76 25
> MNS KRENKEL, LISA R 60 60
> MNS LEONARDELLI, JOHN MICHAEL 143 40 103
> MNS MADSEN, SHANE 24 14 10
> MNS MURPHY, ANTOINETTE J 3 3
> MNS PYELL, CLAUDETTE 11 11
> MNS SCARBOROUGH, MERNA 80 10 70
> MNS WHALEY, LEE 6 6
> */
> "Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote
> in message news:OwD31a1SFHA.580@.TK2MSFTNGP15.phx.gbl...
>