I have a variable that concatenates a file path into a string , and i can't get it to evaluate the concatenation. when i display the value of the variable in a script task, i still see all the double quote marks (see below). I have set the evaluateasexpression for the variable to true.
When i try to use this variable as a sql command, the error is:
"invalid syntax near the +"
(i believe this is the plus sign below the redactedcol3 below)
BTW, is property expressions the only place where you can evaluate a variable's value as you are developing? (expression builder).
This is how the variable displays in the message box in the script component:
"SELECT redactedcol1,redactedcol2,rtrim(" + "'" + #user::LocalPath + " + "'" + "+[redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Not entirely sure this is what you want, but I think it is:
"SELECT redactedcol1,redactedcol2,rtrim("
+ "'"
+ #user::LocalPath
+ "'"
+ " + [redactedcol3]) AS Path FROM dbo.SF_redacted where id=1"
Note the removed extraneous plus sign and double-quote. (I find it helps when concatenating in SSIS to put each part on its own line.)
And I also recommend BIDS Helper, a free tool that includes a better (IMO) expression building GUI, as well as Konesans' Expression Editor which is a like a mini-Intellisense workbench for expressions.
There's also a Variables window in SSIS Projects (View -> Other Windows -> Variables) where you can see the evaluated value of a variable expression.
For others wondering why their expression is not evaluating...
http://www.sqlchicken.com/2012/02/ssis-expressions-not-evaluating-correctly/
Click on the Variable. Make sure "EvaluateAsExpression" is True
Related
example:
"a b c d e f g".Split(" ")[0]
a
when I try to do this same with a function
function MyReturnArray
{
$array = #('a','b','c','d','e','f','g')
return $array
}
MyReturnArray[0] : The term 'MyReturnArray[0]' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ MyReturnArray[0]
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MyReturnArray[0]:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
however, this works:
(MyReturnArray)[0]
a
So the question is, why does the .Split() from a [System.String] Method type not require a grouping () or parenthesise to access the individual element? But with my own function, I must do so. How do I force it to act the same way like with .Split()?
"How do I force it to act the same way like with .Split()?"
The (disappointing) answer is: you don't
Why? Because that's simply not how the language works :)
More complete explanation:
The element access operator [] works on what we might call syntactically bounded expressions (referred to as primary expressions in the PowerShell 3.0 Language Specification, the only official document I know of attempting to document the full grammar of PowerShell).
"a b c d e f".Split() is what we call a member access expression - itself consisting of:
Another bounded expression "a b c d e"
The instance member access operator ., and
A member argument with an argument list Split and ().
Member access expressions are bounded expression - the closing ) is the last possible token the member access operator (the . in the middle) could possibly accept, so we know that the expression ends there.
What makes the string literal "a b c d e f" a bounded expression? Same principle as above, the parser can independently determine the boundaries of the string by looking at the " in front and at the end.
MyReturnArray, however, is not a bounded expression. It's a command expression_, and there are separate parsing rules for command expressions, in order to allow for parameter binding to work the way it does in PowerShell, but also to allow command names to be anything - if you wanted to create a function literally named MyReturnArray[0] then that's absolutely valid.
As you've found, you can enclose it in () parentheses, creating a syntactical boundary for the call to MyReturnArray, the resulting expression of which [] can operate on.
I want to overwrite a zip file in a folder but when i tried the below expression, it is giving an error as:
The expression is not valid and could not be parsed. it might contain invalid elements.
Expression:
#[User::Command_Syntax] = " /c copy " + "\"" + #[User::Output_File_Path_Var] + substring(#[User::Output_Zip_Name_Var], 1, len(#[User::Output_Zip_Name_Var]) - 4) + REPLACE(right(#[User::Output_Zip_Name_Var], 4) , ".zip", "") + ".zip" + "\"" + " " + "\"" + #[User::Archive_File_Path_Var] + substring(#[User::Output_Zip_Name_Var], 1, len(#[User::Output_Zip_Name_Var]) - 4) + REPLACE(right(#[User::Output_Zip_Name_Var], 4) , ".zip", "") + ".zip" + "\""
Can any one please let me know why i'm getting error. Thanks in advance!
I use a tool, which is outside of Visual Studio, which helps troubleshoot expression building. The tool information is here: SQLIS | SSIS Expression Editor & Tester and the github is here: SSIS Expression GitHub
That being said, I copy/pasted your expression above into the editor, added in the # user variables with made-up values in the "Add Variable" ability of the tool, and I get this as my output when evaluating.
So it does seem to evaluate for me, could you verify your user variables are spelled correctly and they are the correct type (string)?
You could also verify the variable assignments during debugging. Here is a good article on how to debug, if needed: Debugging Control Flow in SSIS
I have this field called series that has this expression in it, what does the ' mean in this context?
=(Fields!PropertyID.Value)
'=IIF(Parameters!CombineProperties.Value = TRUE AND (Fields!Campus.Value<>""),Fields!Campus.Value,Fields!PropertyName.Value)
This is an SSRS expression for a label or variable that is parsed at runtime in an ssrs report. The gist here is :
The starting =(Fields!PropertyID.Value) does not make sense as you can't set variables that way, however, after the ' it goes like this:
var result=null;
if (CombineProperties && Campus.Length > 0)
result=Campus
else
result=PropertyName
After reading your post again, I think you are trying to Concatenate strings. Is this your end goal?
=CSTR(Fields!PropertyID.Value) + IIF((Parameters!CombineProperties.Value = True) AND (Fields!Campus.Value<>""), Fields!Campus.Value,Fields!PropertyName.Value)
Update
Doh!, I am rusty on VB. I believe apostrophe comments out a line. Everything after ' is ignored. DOH!
Some files I need to process have this (called the "haves"):
<ApolloDataSet xmlns="http://irisoft.com/ApolloDataSet1.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
Other files in the same group have this (called the "have-nots"):
<ApolloDataSet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
I can set the default namespace for xpath with the below:
.setProperty "SelectionNamespaces", "xmlns:a='http://irisoft.com/ApolloDataSet1.xsd'"
That works for the haves, like a:/Element, but not the have-nots, since the xpath doesn't have the a: alias.
I tried removing the xmlns attribute before processing, in the hopes that I could just use an unaliased path for both, like /Element, but that only worked for the have-nots (the haves just returned nothing).
So is there a way to process both using the same alias, or no alias? I'm trying to either use the same alias for every file, regardless of "xmlns" being listed, or use no alias for either.
Well I resigned to using the workaround I was trying to avoid. But here is an option for this situation until I find a better one. (And forgot to mention - using VBA for this.)
After the domDocument is loaded, I use the getAttribute method to check if the "xmlns" attribute value is null. If it is I form the xpath string with no alias by means of a vbnullstring, which means the xpath query works with the have-not files (i.e. those files with no "xmlns" listed). If it is not null, I use the "xmlns" value to build a string for the setProperty method setting the "SelectionNamespaces" secondary property.
If IsNull(xPOG.DocumentElement.getAttribute("xmlns")) Then
strAlias = vbNullString
Else
strAlias = "a:"
xPOG.setProperty "SelectionNamespaces", _
"xmlns:" & Mid(strAlias, 1, 1) & "='" & xPOG.DocumentElement.getAttribute("xmlns") & "'"
End If
And the resulting processing takes on a rather ugly form of string building that I hoped to avoid.
It sets an IXMLDOMNode to the nodes returned from a selectnodes method using the xPath query with the strAlias variable.
Set xProducts = xPOG.SelectNodes("/" & strAlias & "ApolloDataSet/" _
& strAlias & "Products/" _
& strAlias & "Product/" _
& strAlias & "PR_UPC")
It isn't that it is bad, it just seems to lack elegance & remind me of how little I know sometimes. Which leads me to believe I'm missing some concept that could correct this. But it works, so I'll follow up if I find a better. I did find a kb article that touched on some of the concepts if it helps anyone. I'm using 6.0 though, so good conceptual explanation, just not exactly what I needed.
PRB: MSXML 4.0 Sets the XML Namespace Attribute to an Empty Value for Child Nodes
There is a definite syntax of passing value to crystal-report Formula Field from .Net 4.0- Code
behind
E.g. (C# Code):
Following will NOT work
_rpt.DataDefinition.FormulaFields["fClient"].Text = Mr.Gates;
Following will work-
_rpt.DataDefinition.FormulaFields["fClient"].Text = "\"Mr.Gates\"";
I haven't understand the prominence and way of using following ..
"\" \""
What if "Mr. Gates:" is in some variable, I want to pass!?
plz reply with some code...
Thanks
\" sends a literal " through to the variable. For literal string values in Formulae to be seen as literal strings they must be quoted hence sending the quoted " through is necessary.