I have a column which is defined as varchar(19). So it can have alpha-numeric values.I have cast it to integer. Simple casting will give overflow exception and if I am tring to format it as Z(9) or '999999999' it shows error saying column has combination of numeric, character and GRAPHIC values
I have another casting too for which the column is defined as decimal(13,3) and I need to convert it to integer..I am clue less here too.
Any ideas guys??
VARCHAR(19) would exceed the upper boundary of the INTEGER data type in Teradata.
Try BIGINT or DECIMAL(19,0) instead.
Related
How to insert a varchar into byte(blob) column?
Consider i am having a table A with byte(blob) column 'name'.
INSERT into A (name) values('abc');
throwing error as "617: A blob data type must be supplied within this context."
Need to know whether there is any informix equivalent to below statement in oracle?
utl_raw.cast_to_raw('abc')
There are two very different types — BYTE and BLOB — that you could be asking about. However, the formal message I see for error -617 is:
$ finderr -617
-617 A TEXT or BYTE data type must be supplied within this context.
This statement assigns a value that is not a simple large object to a BYTE or
TEXT column or assigns a BYTE or TEXT column to a column that is not a simple
large object. Neither action is supported. BYTE and TEXT values must be
assigned as whole units to columns of the same type. Check that the statement
specifies the columns that you intended.
$
This indicates that you are using the older 'classic blob' type — BYTE. (There are text large objects too. The older type is TEXT and the newer is CLOB, character large object.)
There isn't currently a built-in way to convert a VARCHAR string to a BYTE (or TEXT). This has been a cause of pain since the BYTE and TEXT types were introduced circa 1990. You don't give any indication of whether you are using Informix ESQL/C, or an ODBC driver, or a JDBC driver, or some other mechanism. If you are using ESQL/C, you have to create a 'locator structure' (loc_t from locator.h) which uses a string representation of the blob — as opposed to various ways of storing the blob data in a file. (I hope you're not on AIX because there are issues with a system-provided loc_t on AIX. It's fairly easily worked around, but it's a nuisance you have to do so.)
I've not tried coding it in ODBC and don't know how to code it in JDBC so I can't pontificate on those.
I'm not so sure about the BLOB 'smart blob' type; there might be a function to convert from string to BLOB (or CLOB) type.
For a dataset in SSRS reports, I've created a calculated field with below expression and it works fine.
=(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value
But sometime we can have factor value as 0. So, I modified above expression with below:
=iif(Fields!Factor.Value = 0,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*1,(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value)
But this throws below exception:
The Value expression for the textrun ‘Textbox2.Paragraphs[0].TextRuns[0]’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type.
Can someone please help to get resolve this issue?
This doesn't seem to be an issue with the IIF, but the datatypes seem to be mismatched. I have a few suggestions to try. First, you could try to multiply the true value by 1.0 as I assume the datatypes are decimal or double. The other option would be to use something like CInt to covert the value to the correct datatype. CInt would likely be inappropriate for decimals as it would round off any decimal values, but the idea is the same. Since your expression doesn't use any aggregates and only uses normal operators, it must relate to something other than the IIF.
Here's a useful link to break down the datatypes and conversion methods. Choose the most appropriate conversion and apply it to the 1.
EDIT: The expression should be the following.
=iif(Fields!Factor.Value = 0.00,
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*CDbl(1),
(Fields!SalesAmount.Value+Fields!TaxAmt.Value)*Fields!Factor.Value)
Say x is a character.
Whenever I do if(x <> '') to know whether the variable is empty or not, it just does not work.
However, when I attempt to do this if(x <> chr(0)), it does work.
I have tried the same thing on two versions of the compiler : Free Pascal and Charm Pascal, but I am still facing the same problem.
There is no such thing as an "empty char". The Char type is always a single character.
That character could be 1 byte AnsiChar representing a value from 0..255. (In Delphi and fpc, it could also be a 2 byte WideChar representing a value from 0..65535.) Either way it is always represented as '<something>'. That "something" must be a character value.
When you compare x <> Chr(0) you are taking the byte value of 0 and converting it to a Char so a valid comparison can be performed.
Side Notes
For Char to reliably have the concept "no value" requires storing additional information. E.g. Databases may have a hidden internal bit field indicating the value is NULL. It's important to be aware that this is fundamentally different from any of the valid values it may have if it's not NULL. Libraries that interact with databases need to provide a way to determine if a value is NULL.
You haven't provided any information about the actual problem you're trying to solve but here are some thoughts that may yield progress:
If you're dealing with user input, it may be more appropriate to compare with a space character ' '.
If you're dealing with characters read from a file, you should probably be checking number of bytes/characters actually read.
If you're trying to determine the end of a string it's much more reliable to use the Length() of the string.
(Though there are some environments that use the convention of treating Char(0) as a special character meaning "end-of-string".) But the convention requires allocating an extra character making the string internally longer than its text length. So the technique is not usable if the environment doesn't support it.
Most importantly, from comments it seems you might be struggling with the difference between empty-string and how that's represented as a Char. And the point is that it isn't. You need to check the length of the string.
E.g. You can do the following:
if (s <> '') then
begin
{ You now know there is at least 1 character in the string so
you can safely read it and not worry about "if it has a value".}
x := s[1];
...
end;
I am getting command line argument when i launch the application.
I am getting four parameter from command line.
after parsing I store them in four std::string/CString(mfc) variable now i need to know whether the value is decimal or not.because these parameter is going to be used in some mathematical calculation.
Can anybody help me on this.
here you can find how to determine if a string is a numeric, in 70 languages!
I'm not sure if all the solutions check the same thing. The C++ implementation checks if the input is a positive/negative integer/floating-point for base 10, or if it a is positive/negative integer for base 8/16. Is that what you want? Do you need to support only positive numbers? Do you need to support floating-points?
Probably you'll need to convert your input strings to numeric value, so there is no reason to do it in two steps (to check, then to convert). Better do it in a single step.
One more thing: If the input string is too long, for example "32525252332912461984612491264912649126129319312931279171295127951275129" - you normally won't want to consider it as a valid input.
Look at every character in the string, and if you find something that is not a digit, or a '.', then it is not a number.
Just use a string->number conversion function that unambiguously reports failure.
e.g. strtod and not atof
In Informix, how can I cast a char(8) type into a money type, so that I can compare it to another money type?
Using "tblAid.amt::money as aid_amt" did not work.
Using "(tblAid.amt * 1) AS aid_amt" did not work.
try this -->
select (disb_amt::NUMERIC) disb_amt from tmp_kygrants;
You may be able to compare the amounts as numeric.
First question - why on earth are you not storing a numeric value in a numeric column? This would make the rest of your question moot. It would also mean that your system will perform better. When you need to store data values, use the obvious type; do not use a string type unless the data is a string.
As already noted, you can use the non-standard Informix cast notation:
SELECT some_column::MONEY FROM WhereEver;
You can also be more careful about the cast type - using MONEY(8,2) for example. You can also use the standard notation:
SELECT CAST(some_column AS MONEY(8,2)) FROM WhereEver;
This assumes you are using IDS 9.x or later -- older products do not support casts at all. However, in general, Informix is pretty good about doing conversions automatically (for example, converting numbers to strings). However, strings are compared lexicographically and not numerically, so a CAST is probably wiser in this context -- but avoiding the need for a cast by using the correct type in the first place is wiser still.
'tis been a while since I played around with informix and I don't have a running instance handy at the moment. However, there are two things that can cause a problem here:
1) since it is a char(8) it can contain values that can not be casted to numeric without a bit of 'cleanup'. E.g. "abc". Or "1,234,567.00".
2) Trailing spaces. (char as opposed to varchar).
What informix error do you get on your explicit cast (::money)?