Note that there are some explanatory texts on larger screens.

plurals
  1. POSSIS Script Task Debugging When Checking Value Comparison
    primarykey
    data
    text
    <p>I have this code in a script task:</p> <pre><code>Public Sub Main() ' ' Add your code here ' Dim MonthFromSQL As String Dim lastMonth As New Date(DateTime.Today.Year, DateTime.Today.Month - 1, 1) Dim rcnt As Integer Dim msg As String 'MsgBox("Month name from SQL is " &amp; CStr(Dts.Variables("MonthNameFromSQL").Value)) rcnt = CInt(Dts.Variables("RowCount").Value) If rcnt = 0 Then msg = "Job returned 0 rows for month " &amp; CStr(MonthName(lastMonth.Month, False)) &amp; " - check with database operator that previous month's data has been loaded into the database." Else msg = "Job returned " &amp; rcnt &amp; " rows - Job Finished" End If 'Pass message variable value out to be used in message Dts.Variables("EmailMessage").Value = msg Dts.TaskResult = Dts.Results.Success End Sub </code></pre> <p>If I modify the IF statement to below to be able to check the month value from SQL DB against system month value it gives me a DTS script error saying that:</p> <blockquote> <p>The type of the value being assigned to variable "User::EmailMessage" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.</p> </blockquote> <pre><code>'First check month name from sql match system last month name If CStr(MonthName(lastMonth.Month, False)) = CStr(Dts.Variables("MonthNameFromSQL").Value) Then MsgBox("Month name variable equals last month value") If rcnt = 0 Then msg = "Job returned 0 rows for month " &amp; CStr(MonthName(lastMonth.Month, False)) &amp; " - check with outpatient database operator that previous month's data has been loaded into the database." Else msg = "Job returned " &amp; rcnt &amp; " rows - Job Finished" End If Else 'Put in code to handle if month values do not match End If </code></pre> <p>I replaced:</p> <pre><code>If CStr(MonthName(lastMonth.Month, False)) = CStr(Dts.Variables("MonthNameFromSQL").Value) Then MsgBox("Month name variable equals last month value") </code></pre> <p>With:</p> <pre><code>If 1=1 Then MsgBox("Month name variable equals last month value") </code></pre> <p>Just to check it would work with a simple comparing statement and that it was something to do with the code I had in the IF statement, as I did not suspect it was anything to do with the msg variable I was populating, even though this was the error message.</p> <p>So I realise it is something to do with:</p> <pre><code>If CStr(MonthName(lastMonth.Month, False)) = CStr(Dts.Variables("MonthNameFromSQL").Value) Then </code></pre> <p>The montNameFromSQL is populated with the result set of a previous SQL task, and then in this script I am using it to check against the system month name. I want to check these values and if a match then success and move onto to check the rows returned, and populate the message to send in my email task.</p> <p>Hopefully it's something simple and a fresh pair of eyes can spot!</p> <p>Thanks</p> <p>Andrew</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload