Casting Error In Powershell(System.Int32) - powershell

I have a problem.
Firstly, There is a MSSQL Database and I sent to query with using PowerShell code. Then I take numbers from these tables (like U056258). After that, I want to mail the people have these numbers. But Powershell sends me an error. Like;
**Cannot convert value "U056258" to type "System.INT32". Error: "Input string was not in a correct format."**
**+CategoryInfo :InvalidArgument: (:) [], RuntimeException**
**+FullyQualifiedErorId :InvalidCastFromStringToInteger**

What is the "U" at the beginning ? Is it an unsigned number ? Remove it.
Ah, your ID isalphanumeric. Guy, don't cast into int32. Or remove the "U" before.

Related

What's the right sintax to search for a X(6) format var in Progress 4gl?

On the statement below I have an error telling me that attribute type is not compatible with. I consult database properties and this attribute format is x(6). Does anyone know which the right sintax to get it ?
P.s. I already tried = '1', EQ 1, EQ '1', = "1" and EQ "1"
FOR EACH bd.tablename WHERE bd.tablename.attribute = "1"
When you say property/attribute, do you mean a field? If you're talking about buffer/table attributes, such as type, for example, the separator should be colon, this -> :
Not period (.), unlike most other OO languages.
But if you're talking about a field, TheMadDBA is correct, and you should check the data type, it's way safer than just the field format.
If you still have this issue, maybe provide more information and we can try to help you further.
The code statement is:
FOR EACH multipos.mp_mvlj WHERE multipos.mp_mvlj.mvl_codmov = 1 NO-LOCK:
The error is (translated from portuguese):
Incompatible Data type in expression or attribution

T-SQL Conversion failed when converting the nvarchar value '12-02' to data type int

I'm trying to convert this NVARCHAR value into a periodeId.
The Raw data could be '12-02'.
My solution for this was first to try this
(1000+CONVERT(INT,LEFT(2,T1.PERIOD_NAME)))*100+CONVERT(Int,RIGHT(2,t1.PERIOD_NAME))
But i get the same error message here and could find any quick solution for it.
I also tried to just do a simple
LEFT(2,T1.PERIOD_NAME) to see if it was the formula itself that crashed it, but the same error came up.
If you want '12-02' to be 1202, then use replace() to remove the hyphen before conversion:
select cast(replace(period_name, '-', '') as int)
In SQL Server 2012+, you should use try_convert(), in case there are other unexpected values.
You can try:
SELECT (1000+CONVERT(INT,LEFT(t1.PERIOD_NAME,2)))*100+CONVERT(Int,RIGHT(t1.PERIOD_NAME,2))
The character_expression that LEFT operates on is at first place, whereas the integer expression that specifies how many characters of the character_expression will be returned, comes at second place.

Decode HResult = -2147467259

Can someone help me decode this HResult? What does it mean? I know the negative stands for a failure. How about the rest of the 10 bits?
I referenced MSDN HResult article here, but I am not sure how to determine what my facility and code bits are.
More info:
_message: "External component has thrown an exception."
Data: {System.Collections.ListDictionaryInternal}
I'll show you how to do it. Paste the negative number into Calculator (Windows) in programmer mode "Dec" setting. Then convert to "Hex" setting. You get the number: FFFFFFFF80004005. The error is 80004005 which is:
0x80004005
E_FAIL
Unspecified
Unfortunately the provider of the function that gave you this error did not categorize the error.
Useful links:
MSDN - HRESULT Format
MSDN - HRESULT Error List
Another way to do it is as follows. An HRESULT should contain a System Error Code in its first 32 bits. Using an AND operation will retrieve the error code from the HRESULT:
int result = (-2147467259 & 0xFFFF)
result is 16389, which is not a part of the System Error Codes list, and as a result, is unspecified.
Print it as an hexadecimal number, then, use for instance, VisualStudio ErrorLookup, to get the message.
-2147467259 in decimal is 80004005 in hexadecimal (usually rendered as 0x80004005). That's "E_FAIL (Unspecified error)" in Win32.
Not a very helpful error code, but maybe it'll get you a half-step closer to a solution.

Condition expression - how to get REPORT TYPE in condition Expression

I would like to write expression like this:
{REPORT_TYPE} == "csv" ? "'" + $F{NUMBER_VALUE} : $F{NUMBER_VALUE}
where {REPORT_TYPE} should be xls, csv etc.
Have you any idea how to get report type?
You need to send a parameter from your server which will get these type of format like csv,xls. If this parameter has some value then you can use this expression. e.g. you have a parameter named reportType then you can make a syntax like this.
$P{reportType} ? "'" + $F{NUMBER_VALUE} : $F{NUMBER_VALUE}
if you want report type like csv then you need to give a value to this parameter, otherwise send it as blank string.
If you still get problem let me know.

Display blank value ("") as date in SSRS

I have the column DiscontinuedDate with either a datetime or a blank value. I used the expression
FormatDateTime(Fields!DiscontinuedDate.Value, DateFormat.ShortDate)
To show the date time as just a date but then when the value is blank it shows as an error with the following message "Conversion from string "" to type 'Date' is not valid."
So i've been trying to use an IIF expression like the below:
=IIF(Fields!DiscontinuedDate.Value is "", "", FormatDateTime(Fields!DiscontinuedDate.Value, DateFormat.ShortDate))
I've tried a few variations but they all bring back the same error. Any ideas?
Thanks,
Adam
Your issue is that SSRS IIf expressions do not short circuit, so whenever you have a blank string your code will still be trying the FormatDateTime conversion, so you get this error even with your check.
You can add some logic to stop the empty string being evaluated in the FormatDateTime expression by using another IIf to change it to a NULL value, which won't fail:
=IIF(Fields!DiscontinuedDate.Value = ""
, ""
, FormatDateTime(IIf(Fields!DiscontinuedDate.Value = ""
, Nothing
, Fields!DiscontinuedDate.Value)
, DateFormat.ShortDate))
That solves your immediate issue, but assuming the underlying data is text based, I would also recommend looking at your underlying data and using explicit DateTime type data types instead of strings to prevent these at the lowest possible level.