Using Trim and InStr, I have written an MS Access query to extract data from a field. The query works as designed to extract the desired data, however I receive a #FUNC! error when the field I am extracting from is blank.
I have attempted nz and an IIF statement - neither worked.
Current code:
ExprA: Trim(Left([Target],(InStr(1,[Target],"=")-1)))
Any ideas on how to edit this query to prevent the #FUNC! error from appearing for blank/null values?
Thanks!
You can "cheat" a little:
ExprA: Trim(Left([Target],(InStr(1,[Target] & "=","=")-1)))
You can check if [Target] contains "=" with IIF():
IIF(
InStr(1,[Target],"=") > 0,
Trim(Left([Target],(InStr(1,[Target],"=")-1))),
[Target]
)
This code will return the whole [Target] column's value if [Target] does not contain "=" and will not throw an error if the column is NULL.
Related
I have IIf expression given below. Normally it works the way I want, but It gives an error when I do not enter appropriate numeric data. So, I want it to be blank or symbol, etc. when I do not enter a suitable value for the calculation. Many many thanks for your answers.
=IIf(Mid([EBGA];4;1)="/";IIf(Abs(Mid([EBGA];1;3)-400)>Abs(Mid([EBGA];5;3)-400);Format([KA1]/Mid([EBA1];InStr([EBA1];"/")+1;10);"Fixed");Format([KA1]/Mid([EBA1];1;InStr([EBA1];"/")-1);"Fixed"));Format([KA1]/[EBA1];"Fixed"))
If InStr() returns Null, Mid() will error because its position arguments must be numeric. If field used by InStr() is Null, InStr() returns Null. Handle possibility of Null.
InStr(Nz([EBA1], ""), "/")
Arithmetic with Null will return Null.
I'm having a little trouble with an SSIS expression where, in a Derived Column Transformation Data Flow Task, I am attempting to grab a 6 character substring from a string input, casting the derived columns value to NULL if it doesn't exist. This is the code I am using, with line breaks and indentation added for readability:
KeyValueLength == -2 ?
NULL(DT_STR,6,65001) :
(
KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
)
(For reference, when KeyValueLength is -2 the key value is not found, when it is -1 then it is found at the end of StringInput, any other number and it is found in the middle of StringInput. This code works for other key values I'm getting that are casting to DT_I4 and DT_DECIMAL)
Individually, the following three expressions do not generate an error:
NULL(DT_STR,6,65001)
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999))
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength)
But when put together in that nested conditional above, I get the following error when trying to save the window:
For operands of the conditional operator, the data type DT_STR is
supported only for input columns and cast operations. The expression
"KeyValueLength == -2 ? NULL(DT_STR,6,65001) : (KeyValueLength == -1 ?
(DT_STR,6,65001)RTRIM(SUBSTRING(StringInput,KeyValueStart,999)) :
(DT_STR,6,65001)SUBSTRING(StringInput,KeyValueStart,KeyValueLength))"
has a DT_STR operand that is not an input column or the result of a
cast, and cannot be used with the conditional operation. To perform
this operation, the operand needs to be explicitly cast with a cast
operator.
I'm having a little trouble figuring out exactly what the issue is here. That error message suggests it's to do with the use of conditionals, but I'm not seeing the problem.
So, in the infinite wisdom of Microsoft, this is null as a DT_STR and perfectly valid as a direct value assignment:
NULL(DT_STR,6,65001)
But if you want to assign that value in a conditional where all eventual conditions must be the same type you have to do this:
(DT_STR,6,65001)NULL(DT_STR,6,65001)
The same does not apply for other types, where something like NULL(DT_I4) is valid irrespective of whether it is directly assigned or assigned via condition. SMH
I keep getting a syntax error using Microsoft Access. I believe I am putting in the iif statement incorrectly. I am even using the expression builder. However, it keeps saying that there may be a misplaced comma
Please help
Respectfully,
In Design View instead of , use ; in the IIF() function:
IIf([LastName]="Smith";1;0)
If you see the query in SQL View though, you will see the function with commas.This is a case applying to regions where the comma could be a decimal separator (check your regional settings of your PC).
The error is not due to the use of the comma in place of a semi-colon, but rather because you have set the Table row to Orders within the query grid:
As such, the query is attempting to access a field called [iif([LastName]="Smith",1,0)] from the table Orders, and this is an invalid field name.
Since you are using a calculated field which isn't being sourced directly from any particular table, clear Orders from the table row for this field to fix the error.
I am trying to perform a simple task in SQL Server and receiving an error. I have a table called World.Internet_CountryYear. The table has year columns (i.e. 1960, 1965, etc.) with numerical data in the fields, but the data type for the columns is varchar(max). Currently, the fields that do not have data have "" in them, which I would like to replace with 0.00. So, I try to run a simple update command as follows:
UPDATE World.Internet_CountryYear
SET 1960 = '0.00'
WHERE 1960 = '""'
For some reason, I receive an error saying "Incorrect syntax near '1960'"
Is there a problem with the DDL of this table? What am I missing here? I have tried specifying World.Internet_CountryYear.1960 as well, but still receive a similar error: Incorrect syntax near '.1960'
Any suggestions?
Enclose the column name with square brackets (you need to use the square brackets when you are using skeywords, special characters in the column names)
Try this:
UPDATE World.Internet_CountryYear
SET [1960] = '0.00'
WHERE [1960] = '""'
I am using front end as Business Objects and backend MS Access database. I have one field with following syntax and when i pull this field in query getting error like "Too Few Parameters Expected 1"
Format(Votes.`Vote Received`,"yyyymm")
This syntax is parsing but when pulled this object in query giving error. I think it's something related to quotes on field name but this how that field is named. When i am pulling just below field query not giving error.
Votes.`Vote Received`
Appreciate your inputs..
It seems you wish to convert a year and month to two digits each without using format.
"anyway to convert month number to two digit (01-12) without using format function..When i have used Year(date)&Month(date), its giving result but like 20111"
I suggest you try:
Right(Year(Votes.`Vote Received`),2) & "-" & Right("00" & Month(Votes.`Vote Received`),2)