Database Administrators
Q&A for database professionals who wish to improve their database skills
Latest Questions
0
votes
1
answers
197
views
Logging the conditions within a conditional split transformation (SSIS in SQL Server 2012 and 2016)
I'm struggling to find out how we can store the conditions inside a conditional split transformation when we run a package. I need a snapshot of the expressions (the whole expressions, not only parameters inside them). The closest we have got is when an error triggered the SSIS logging and stored th...
I'm struggling to find out how we can store the conditions inside a conditional split transformation when we run a package. I need a snapshot of the expressions (the whole expressions, not only parameters inside them).
The closest we have got is when an error triggered the SSIS logging and stored the context in the table event_message_context, but we can't figure out how to trigger this logging without an error. We don't need it specifically to come from the built-in logging, we can surely use a script task if you have any suggestions. We run both SQL server 2012 and 2016.
NikolaiH
(1 rep)
Sep 25, 2018, 08:32 PM
• Last activity: Jun 25, 2025, 05:04 AM
0
votes
1
answers
270
views
SSIS Variables as expressions to generate Start and end dates of a quarter with input year and month passed as variable
Can someone help me create SSIS expressions for variables to generate QuarterStart(DateTime) and QuarterEnd(DateTime) as a variable with year(int32) and quarter(int32) passed on as user variables. The equivalent T-SQL script would be ```DECLARE @FISCAL_YEAR INT = 2023, @QUATER INT = 1 SELECT DATEFRO...
Can someone help me create SSIS expressions for variables to generate QuarterStart(DateTime) and QuarterEnd(DateTime) as a variable with year(int32) and quarter(int32) passed on as user variables.
The equivalent T-SQL script would be
@FISCAL_YEAR INT = 2023,
@QUATER INT = 1
SELECT
DATEFROMPARTS(@fiscal_year,(@Quater * 3)-2,1) AS QuaterStart,
EOMONTH(DATEFROMPARTS(@fiscal_year,@Quater * 3,1)) AS QuaterEnd
mk SQL
(5 rep)
Jan 29, 2024, 03:21 AM
• Last activity: May 21, 2025, 01:01 AM
1
votes
1
answers
831
views
How to create Destination table name with Getdate in SSIS OLEDB destination
How to create Destination table name with Getdate in ssis destination task. I have one table like Test..but i want to create new table like Test_09Feb2023 in OLEDB destination.
How to create Destination table name with Getdate in ssis destination task.
I have one table like Test..but i want to create new table like Test_09Feb2023 in OLEDB destination.
karthik sanapala
(37 rep)
Feb 9, 2023, 06:49 AM
• Last activity: Nov 15, 2024, 09:07 AM
4
votes
1
answers
15198
views
How do I map SSIS 2012 Package Variables to Parameters?
I have created multiple packages that use variables to assign Connection Manager `Expressions` such as `Connection String`. However in the new SQL 2012 [Project Deployment Model][1] I don't seem to be able to configure these variables. Would I therefore need to create these `Parameters` for the `Env...
I have created multiple packages that use variables to assign Connection Manager
-----
Update: I've now cut-over to using Project-level and Package-level Parameters (instead of Package Variables) when I need to modify per-environment settings such as file paths and connection strings. Perhaps this was the intent from MS: any best practice advice is of course, still welcome.
Expressions
such as Connection String
. However in the new SQL 2012 Project Deployment Model I don't seem to be able to configure these variables.
Would I therefore need to create these Parameters
for the Environment
and map them to specific Package Variables
? Is this even possible and how is this done?
This link describes configuring the Parameters
, but not associating to **package** Variables
.
Further to this, it seems I *could* set a Varaiable Expression
to be a Project or Package Parameter
, however this seems a bit convoluted. Perhaps I should stop using Variables
altogether?

PeterX
(177 rep)
Dec 17, 2013, 06:57 AM
• Last activity: Mar 31, 2024, 05:31 AM
-2
votes
1
answers
1362
views
How to convert default Date format from MM/DD/YY to YYYY/MM/DD HH:MM:SS in SSIS packages?
I don't know what to write in Derived column expression. Steps- 1.Source - Excel file 2.Derived column 3.Destination - OLE DB Destination
I don't know what to write in Derived column expression.
Steps-
1.Source - Excel file
2.Derived column
3.Destination - OLE DB Destination
Sharana Jyothi B
(1 rep)
Nov 8, 2021, 01:54 PM
• Last activity: Nov 8, 2021, 03:38 PM
0
votes
0
answers
760
views
SSIS Dynamically Loop through SQL Tables
I have been fighting with an SSIS package for sometime now. I **did** successfully build a package that will extract data from a specific table by creating a date list from a script task, use a forEachLoop container to loop through the date list variable and create daily files. Package then uploads...
I have been fighting with an SSIS package for sometime now.
I **did** successfully build a package that will extract data from a specific table by creating a date list from a script task, use a forEachLoop container to loop through the date list variable and create daily files. Package then uploads them to S3 and deletes the data from the SQL table.
I am now trying to build this dynamically that will loop through a list of audit tables.
Tables will have different retention periods and different column structures.
So far I have created a SQL archive maintenance table that has a list of the tables and retention days, idea being we won't need to alter the SSIS package if we want to change the retention periods +/-
Script task that selects the list from the archive maint table and drops the output into a variable that is connected to a ForEachLooper container. I then planned to have another execute SQL task within the ForEachLooper container using the ? in my SQL statement to identify the user::tablename variable. After reading I understand I cannot just add the user::tablename variable as ? and I need to create it as an expression, or at least this was one suggestion.
I have tried the expression below, the variables are strings, I made he mistake originally where they were objects.
"SELECT DISTINCT CONVERT(VARCHAR, DateTimeModified, 23) AS ShortDate FROM " + @[User::ArchTableName] + " WHERE DateTimeModified <= DATEADD(MONTH, " + @[User::ArchTableRetentionDays] + ",GETDATE())
Trying to evaluate this I get an error
I am sure I have missed a step or have made a glaring error.
It may also be I am way off track with this as an idea, I also realise I need dynamically build the column lists of the tables as they are not the same structures but I am ignoring that until this is working.
If anyone has any advice or guidance I would appreciate it.
If there are ways to improve the question I am also open to suggestions.

Stockburn
(501 rep)
Sep 7, 2021, 06:15 AM
0
votes
1
answers
3533
views
Looking for solution to add double quotes in field which has commas in SSIS
I have a field called something like TYPE & the values are variant in it. I want the SSIS to export the result to CSV & while exporting, if it finds the , in column TYPE only that line/value should be double quoted. Eg: TYPE Begin Bag 1,000 mL Miscellaneous 20ml Final 2,000 mL Begin Bag 1 mL the res...
I have a field called something like TYPE & the values are variant in it. I want the SSIS to export the result to CSV & while exporting, if it finds the , in column TYPE only that line/value should be double quoted.
Eg:
TYPE
Begin Bag 1,000 mL
Miscellaneous 20ml
Final 2,000 mL
Begin Bag 1 mL
the result should be (in the csv format exported):
TYPE
"Begin Bag 1,000 mL",
Miscellaneous 20ml,
"Final 2,000 mL",
Begin Bag 1 mL
I tried using the Derived column "\""+ TYPE +"\"" but that just adds Double quotes to every value for column TYPE.
Please help!
THanks,
Atulya
Atulya
(1 rep)
Dec 4, 2018, 08:49 PM
• Last activity: Jan 29, 2019, 12:38 AM
2
votes
1
answers
24556
views
SSIS Derived Column Casting to DT_STR
Why can't I get this to cast as a DT_STR - the data source is WSTR, but shouldn't this cast make the output DT_STR? [![Here is the Formula][1]][1] `(IPUNSPSC) =="**no_UNSPSC_available**" ? (DT_STR,20,1252)NULL(DT_STR,20,1252) : (DT_STR,20,1252)TRIM(IPUNSPSC)` [1]: https://i.sstatic.net/hQZ7Q.png
Why can't I get this to cast as a DT_STR - the data source is WSTR, but shouldn't this cast make the output DT_STR?

(IPUNSPSC) =="**no_UNSPSC_available**" ? (DT_STR,20,1252)NULL(DT_STR,20,1252) : (DT_STR,20,1252)TRIM(IPUNSPSC)
Steve Britton
(67 rep)
Jul 5, 2017, 05:05 PM
• Last activity: Jun 26, 2018, 01:59 AM
0
votes
1
answers
5214
views
SSIS - Disable Task Based on Variable Value
I have an SSIS package that runs a number of **Data Flow Tasks** all at the same time. Each **Data Flow Task** is placed inside a Sequence Container. Before the **Data Flow Tasks** are run, a **Script Task** is used to check what **Data Flow Tasks** are required to run. Each **Data Flow Task** also...
I have an SSIS package that runs a number of **Data Flow Tasks** all at the same time.
Each **Data Flow Task** is placed inside a Sequence Container.
Before the **Data Flow Tasks** are run, a **Script Task** is used to check what **Data Flow Tasks** are required to run.
Each **Data Flow Task** also has a related variable, which is set to true or false by the **Script Task**. The Data Flow Tasks use the variable value as a *Disable Expression* property.
When run initially, the process works as expected. Those Tasks that have variable value = true do run, and those that have a variable value = false do not run.
However, the next time I go to run the package all **Data Flow Tasks** are disabled initially (probably because the related variables are set to false).
But even when some variables are then set to true at runtime, the Tasks remain disabled. The *Disable Expression* does not seem to pick up the latest variable value. (in the Watch window I can see the variable values have updated correctly)
I tried setting '*DelayValidation*' *= true* on each Task but no change.
Any reason why this happens?

Kevin
(533 rep)
Feb 22, 2018, 01:56 PM
• Last activity: Feb 22, 2018, 02:41 PM
1
votes
0
answers
402
views
flat file datetime issue
I have a flat file with this datetime format `5/24/2017 05:12:44.243 PM`. I have been struggling to convert this format to something like this `2017-05-24 17:12:44.243`. I tried using this derived column expression (DT_DBTIMESTAMP)(SUBSTRING(EventDate,FINDSTRING(EventDate,"/",2) + 1,4) + "-" + SUBST...
I have a flat file with this datetime format
5/24/2017 05:12:44.243 PM
. I have been struggling to convert this format to something like this 2017-05-24 17:12:44.243
. I tried using this derived column expression
(DT_DBTIMESTAMP)(SUBSTRING(EventDate,FINDSTRING(EventDate,"/",2) + 1,4) +
"-" + SUBSTRING(EventDate,1,FINDSTRING(EventDate,"/",1) - 1) +
"-" + SUBSTRING(EventDate,FINDSTRING(EventDate,"/",1) +
1,FINDSTRING(EventDate,"/",2) - FINDSTRING(EventDate,"/",1) - 1) +
" " + SUBSTRING(EventDate,FINDSTRING(EventDate," ",1) + 1,8))
where "EventDate" is the column name
but I am getting the result in this format "2017-05-22 05:21:00.000" also this is not converting the 12 hour to 24 hour. I am new to SSIS development and been struggling on this really long. Please help me on this, any help will be really appreciated.
gdw
(69 rep)
Jul 12, 2017, 09:55 PM
• Last activity: Jul 12, 2017, 10:51 PM
6
votes
3
answers
2572
views
SSIS 2012 VS_ISBROKEN on Derived Column
I have converted a SSIS package built in VS2008 to open in VS2010. I have a Derived Column component that fails validation. It works fine in VS2008. Here is the Expression used in Derived Column... FINDSTRING( SecurityDescription,"\n",1) > 0 ? SUBSTRING(SecurityDescription, 1, FINDSTRING(SecurityDes...
I have converted a SSIS package built in VS2008 to open in VS2010.
I have a Derived Column component that fails validation. It works fine in VS2008.
Here is the Expression used in Derived Column...
FINDSTRING(
SecurityDescription,"\n",1) > 0
? SUBSTRING(SecurityDescription, 1,
FINDSTRING(SecurityDescription,"\n",1) - 1)
) : SecurityDescription
Below are the errors when I run the package...
Error is:
>[Derived Column ] Error:
Attempt to parse the expression
"

[FINDSTRING](#102,"\n",1) > 0 ? [SUBSTRING](#11898,1,[FINDSTRING](#11898,"\n",1) - 1) : #102
" failed and returned error code 0xC00470A3.
The expression cannot be parsed. It might contain invalid elements or it might not be well-formed. There may also be an out-of-memory error.
I have double checked and SecurityDescription
is a valid column. It works fine if I just add SecurityDescription
. Not sure what is wrong with the FINDSTRING
code.
K09
(1454 rep)
Jan 31, 2017, 12:34 PM
• Last activity: May 6, 2017, 07:21 AM
-1
votes
1
answers
1444
views
How to format SSIS Expression for weekend
I have the following format to account for weekends while naming an excel output. How do I get only the date and not the full startime formatted like 20150429? ((DT_I4)DATEPART("weekday",@[System::StartTime]) ==2 ? Replace((DT_STR, 20, 1252)(DATEADD( "D", -3,@[System::StartTime])),":","") + ".xlsx"...
I have the following format to account for weekends while naming an excel output. How do I get only the date and not the full startime formatted like 20150429?
((DT_I4)DATEPART("weekday",@[System::StartTime]) ==2 ?
Replace((DT_STR, 20, 1252)(DATEADD( "D", -3,@[System::StartTime])),":","") +
".xlsx" :
Replace((DT_STR, 20, 1252)(DATEADD( "D", -1,@[System::StartTime])),":","") +
".xlsx")
gaktheknife
(123 rep)
Apr 29, 2015, 01:04 PM
• Last activity: Apr 29, 2015, 04:21 PM
2
votes
1
answers
1337
views
convert string allow null col to int?
I want to convert string to int my string type [DT_WSTR] and my expression ISNULL(col) || TRIM(col) == "" ? (DT_I4)0 : (DT_I4)col I get this error [Derived Column [518]] Error: The conditional operation failed.
I want to convert string to int my string type [DT_WSTR] and my expression
ISNULL(col) || TRIM(col) == "" ? (DT_I4)0 : (DT_I4)col
I get this error
[Derived Column ] Error: The conditional operation failed.
NinjaDeveloper
(245 rep)
Sep 19, 2014, 07:44 PM
• Last activity: Sep 23, 2014, 02:48 AM
1
votes
1
answers
5714
views
SSIS: Get Date for Day of the Week
In SSIS, how do I get the date for a specific day of the week? For example, how do I get last Sunday's date? I assume I have to do some subtraction on the day-of-week, but not sure: DATEADD("d", -DATEPART("DW", GETDATE()), GETDATE())
In SSIS, how do I get the date for a specific day of the week? For example, how do I get last Sunday's date?
I assume I have to do some subtraction on the day-of-week, but not sure:
DATEADD("d", -DATEPART("DW", GETDATE()), GETDATE())
PeterX
(177 rep)
Feb 7, 2014, 05:57 AM
• Last activity: Mar 12, 2014, 03:57 PM
2
votes
1
answers
5970
views
ssis convert ddmonyyyy dd/mm/yyyy
Hi guys trying to convert 16JAN2014 --> 16/01/2014. Any ideas??? i'm trying to avoid the horrendous expression of ? JAN : 1 ? FEB : 2 etc. etc. SSMS will quite happily do SELECT MONTH('16JAN2014') to get me the number of month however MONTH( "16JAN2014" ) will not work in SSIS. hmmm... tried code bu...
Hi guys trying to convert
16JAN2014 --> 16/01/2014. Any ideas??? i'm trying to avoid the horrendous expression of ? JAN : 1 ? FEB : 2 etc. etc.
SSMS will quite happily do SELECT MONTH('16JAN2014') to get me the number of month however MONTH( "16JAN2014" ) will not work in SSIS.
hmmm... tried code but keep getting error below...

jhowe
(271 rep)
Jan 16, 2014, 02:15 PM
• Last activity: Jan 16, 2014, 05:42 PM
2
votes
1
answers
6456
views
SSIS Event Handler at Package Level
I have a fairly simple SSIS package (handful of Execute Task and a few Data Flow task). The end result I am looking to have: - I would like to get notified by email when an error occurs anywhere in the package - I would like that email to include: Package name, failed task, and error information. As...
I have a fairly simple SSIS package (handful of Execute Task and a few Data Flow task). The end result I am looking to have:
- I would like to get notified by email when an error occurs anywhere
in the package
- I would like that email to include: Package name, failed task, and error information.
As I understand I set this up in the following manner:
1. Create an Event Handler for
Subject -
MessageSource - (line breaks added for readability)
OnError
for the package level (Excutable is set to the package name).
2. Configured the SMTP connection and added in an Send Mail Task
3. Within that task I configured an expression for the Subject
and MessageSource
. Those two expressions are noted below.
Expressions:
Subject -
"Error occurred on " + @[System::PackageName]
MessageSource - (line breaks added for readability)
(DT_WSTR,250)("An error occurred in execution of the package: " + @[System::PackageName] + "\n" +
"The task that experienced the error: " + @[System::TaskName] + "\n" +
"The error information returned:\n" +
"Error Code: " + (DT_WSTR,50)(@[System::ErrorCode]) + "\n" +
"Error Description: " + @[System::ErrorDescription])
Now what occurred after I forced an error:
1. Task failed as expected, but the event handler failed as well.
2. OnError
event fired, except not as expected. First issue is truncation, received error A truncation occurred during evaluation of the expression
. This is the content of the email received, which I don't see the expected new lines:
An error occurred in execution of the package: The task that experienced the error: Failure notification The error information returned:
Error Code: 0
Error Description:
3. Second error for the same OnError: property "MessageSource" cannot be evaluated. Modify the expression to be valid.
4. I received two emails when the task failed.
Environment Info: SQL Server 2008 R2, running the package through BIDS only at this time.
Questions:
1. What do I have wrong in the expression for the MessageSource
? I can obviously evaluate the expression successfully in the properties window, and understand that is because the variables are not populated. So how do you configure that were it will not truncate no matter what error is passed in, just set it to some large number length?
2. I am not looking for some custom method or code to perform this as the package is fairly simple and is only run every blue moon. However, would it be best to simply create an OnError
event for each task? As I understand it any child task that fails has the error information passed up to the parent package, so it should work right?
user507
Nov 11, 2013, 03:51 PM
• Last activity: Nov 11, 2013, 04:51 PM
Showing page 1 of 16 total questions