SSIS Derived Column translated from SSMS query - ssis

New to SSIS, been dealing with SSMS mostly. Anyone can help translating the below SSMS statement into SSIS Derived Column Transformation? Many thanks.
ReliabilityFactorInput = Case
When (isnull(pn.LBOXMATL, 'OTHER') = 'OTHER' AND (round(ISNull(edd.cal_year, eqd.YearManuf) + 1, -4)/10000<=2003) OR pn.LBOXMATL ='Cast Iron') AND (ceiling((pn.NOWAYS+1)/2)*2 >= 4) then '1.3'
When (isnull(pn.LBOXMATL, 'OTHER') = 'OTHER' AND (round(ISNull(edd.cal_year, eqd.YearManuf) + 1, -4)/10000<=2003) OR pn.LBOXMATL = 'Cast Iron') AND (ceiling((pn.NOWAYS+1)/2)*2 < 4) then '1.1'
else ''
End

1.Name a variable with whatever name you want with int data type
2.Use execute sql task
3.copy all the complete query into that task and specify the result Set to single row
4.Switch to Result Set page, choose the variable you create, and set the result name to 0
5.Now every time you run the package the variable will be assigned either 1.3 or 1.1
That variable could be used in Derived Column transformation in data flow now

Related

SSIS execute sql statement multiple steps

In my SSIS pacakge I have an Execute SQL Task with 2 statements:
statement 1:
select coalesce ( max (id), 0)+1 as ID from AAA
statement 2:
Insert into BBB (id) values (?)
In the first statement, I saved the result to an variable ID, and in the 2nd statement, I use this variable ID to insert into BBB id column. Let's say the result of the first statement should be 4, however, after I query table BBB, i found what inserted into BBB is 0.
Did I miss anything here?
Running the first statement generates the result of 1 for an empty table.
The default value for an integer in SSIS is going to be 0.
It would lead me to believe that you are not assigning the result from an Execute SQL Task properly.
Either drop in an Script Task to print the value via information events
public void Main()
{
bool fireAgain = false;
string message = "{0}::{1} : {2}";
foreach (var item in Dts.Variables)
{
Dts.Events.FireInformation(0, "SCR Echo Back", string.Format(message, item.Namespace, item.Name, item.Value), string.Empty, 0, ref fireAgain);
}
Dts.TaskResult = (int)ScriptResults.Success;
}
Or set a breakpoint on the second Execute SQL Task to identify the current value of the variable.
If the value is set correctly, then the only remaining point of failure is the second Execute SQL Task where it would imply you do not have your variable mapped.
As your code sample uses a question mark ? as the place holder, it becomes a question of whether the connection manager is OLEDB in which we have a zero based ordinal system or ODBC in which we have a one based ordinal.
If the problem exists on the first step, then be certain that you have used the correct 0/1 value as the "name" of the result column

SSRS Parameter show 1 and 0

Using SQL Server 2016 & SSRS. I may be missing something simple here, but I have a field (called Errors) in a report that has an Integer value of either 0 or 1.
I've added a parameter to my SSRS report called Errors and added 3 options:
1 = show error
0 = no error
1 or 0 = both
The Both option is not working - it doesn't return any records. I must be missing something. In Available Values I have a Label called 'Both'. On the value I enter the expression:
= 1 OR 0
What am I missing?
The parameter doesn't work the way you want it to.
The 1 or 0 value is probably being evaluated as a text value.
My suggestion is to use -1 for both if it can't be in the data and change your parameter to an integer.
If you are using the parameter in a query, you add an OR to check for your both selection (-1).
WHERE (ERROR_FIELD = #ERRORS OR #ERRORS = -1)
This will check to see if the field matches the parameter or if the parameter = -1.
If you are using the FILTER on the dataset or table,
=IIF(Fields!ERROR_FIELD.Value = Parameters!ERRORS.Value OR Parameters!ERRORS.Value = -1, 1 , 0)
And set the Type to Integer and the value to 1.
If anyone is interested, I got this working using an IN within the WHERE:
WHERE ERROR_FIELD IN (#Error)

Hiding table or assigning temp data based on visibility expression ssrs 2008

I have a table in ssrs 2008. This table has a row visibility expression like:
=IIF(max(Fields!VExpected.Value) <> "", 1, 0) +
IIF(max(Fields!MExpected.Value) <> "", 1, 0) +
IIF(max(Fields!PExpected.Value) <> "", 1, 0) = 3, false, true)
Sometimes the datasource returns no data, or the returned data is not matching with this expression. In this case what I see is that a table with borders and column names but no data on it like:
id Vex Mex Pex
However, I want to show it as
id Vex Mex Pex
- - - -
Or if possible:
id Vex Mex Pex
No Data
Another question is, is there any way to hide the complete table if there is no returning data or any matching data with the expression?
Thanks
You can use CountRows function to determine how many rows your dataset is returning. If it is zero hide the table otherwise show it.
=iif(CountRows("DataSetName")=0,true,false)
Replace DataSetName by the actual name of your dataset.
For not matching expression data you can use the this expression.
=IIF(
max(Fields!VExpected.Value) <> "" AND
max(Fields!MExpected.Value) <> "" AND
max(Fields!PExpected.Value) <> "",False,True
)
The whole expression for matching expression and no rows cases could be something like this:
=Switch(
CountRows("DataSetName")=0,true,
max(Fields!VExpected.Value) = "",true,
max(Fields!MExpected.Value) = "",true,
max(Fields!PExpected.Value) = "",True,
true,False
)
Supposing VM, ME and PE expected values are numeric type I'd use ISNOTHING() function to determine when null values are being returned.
=Switch(
CountRows("DataSetName")=0,true,
ISNOTHING(max(Fields!VExpected.Value)),true,
ISNOTHING(max(Fields!MExpected.Value)),true,
ISNOTHING(max(Fields!PExpected.Value)),True,
true,False
)
Additional you can set a message when no rows are being returned from your dataset. Select the tablix and press F4 to see properties window. Go to NoRowsMessage property and use an expression to say your users there is no data.
="There is no data."
In this cases the tablix will not appear in your report but the message you set will be rendered in the location where the tablix should be.
Let me know if this helps.

How to increase the user' error times? unknown whether the original value is null

Before operate Access database,in the SQL express,I can just use this statement and it works very well:
UPDATE Person
SET FErrorTimes = IsNull(FErrorTimes, 0) + 1
WHERE (FUserName = #name)
by now, it reports as error syntax
can someone help me please,and thanks very much.
Access' IsNull is different than SQL Server's IsNull. In Access, IsNull accepts only one argument, and returns True or False to indicate whether that argument evaluates as Null.
Use one of these instead.
UPDATE Person
SET FErrorTimes = Nz(FErrorTimes, 0) + 1
WHERE FUserName = #name
UPDATE Person
SET FErrorTimes = IIf(FErrorTimes Is Null, 0, FErrorTimes) + 1
WHERE FUserName = #name
Note Nz() is only available for a query run within an Access session. If you're running a query from external code which connects to the Access db, use the second example.

how to handle dynamic input values in sql server 2008 query

how to handle dynamic input values in sql server 2008 query.
My scenario is in the below query is im having two input paramanetrs passing from java through i-batis
1) if i enter stlmtTransId field alone query should execute (paymentTransId is empty now).
2) if i enter paymentTransId field alone query should execute(stlmtTransId is empty now).
3) if i enter both input values query should execute for matching the two inputs.
at any of abovr case i need output. how to handle it.
SELECT
STLMT_TRANS.SETTLEMENT_TRANSACTION_ID
,STLMT_TRANS.PC_TRANSACTION_ID
,STLMT_TRANS.TRANSACTION_AMOUNT
,STLMT_TRANS.PAYMENT_AGENT_ID
,STLMT_TRANS.PAYMENT_AGENCY_ID
,STLMT_TRANS.PAYMENT_TRANS_DATE
FROM
T_SETTLEMENT_TRANSACTION STLMT_TRANS WITH (NOLOCK)
WHERE
STLMT_TRANS.SETTLEMENT_TRANSACTION_ID=#stlmtTransId#
AND
STLMT_TRANS.PC_TRANSACTION_ID=#paymentTransId#
Note: im using java + I-Batis
WHERE
(
(STLMT_TRANS.SETTLEMENT_TRANSACTION_ID=#stlmtTransId#) or (#stlmtTransId# is NULL)
)
AND
(
(STLMT_TRANS.PC_TRANSACTION_ID=#paymentTransId#) or (#paymentTransId# is NULL)
)
SELECT
STLMT_TRANS.SETTLEMENT_TRANSACTION_ID
,STLMT_TRANS.PC_TRANSACTION_ID
,STLMT_TRANS.TRANSACTION_AMOUNT
,STLMT_TRANS.PAYMENT_AGENT_ID
,STLMT_TRANS.PAYMENT_AGENCY_ID
,STLMT_TRANS.PAYMENT_TRANS_DATE
FROM
T_SETTLEMENT_TRANSACTION STLMT_TRANS WITH (NOLOCK)
WHERE STLMT_TRANS.SETTLEMENT_TRANSACTION_ID = ISNULL(#stlmtTransId, STLMT_TRANS.SETTLEMENT_TRANSACTION_ID)
AND STLMT_TRANS.PC_TRANSACTION_ID = ISNULL(#paymentTransId, STLMT_TRANS.PC_TRANSACTION_ID)