I am trying to query two internal sheets within excel,
I want to use this following statement,
cast('double', NULL) AS field1
When i remove the above line, my query works.
I get error Method 'Execute' of object' _Connection' failed . Double is the data type. The field should be null for now, but later a large number will be used in field1.
Have you tried isnull('double', NULL) AS field1 or coalesce('double', NULL) AS field1.
Related
I am trying to use Access to convert a table with a column of string into Currency if the string expression is valid.
My Input
line data
--------------
8 Date
9 66.00
My query
SELECT line, CCur([data]) AS data
FROM Input;
My query output is
line data
--------------
8 #Error
9 $66.00
My ideal output is
line data
--------------
9 $66.00
I would like filter our the #Error in query. However, when I use the criteria field (i.e. >0), it prompts me Data type mismatch.
I also tried to use IsError() or IsNumeric() with IIF to catch the error. However, it still shows the #Error in the output.
I also found in post that Nz() could help. Still, the same #Error in my case.
Is there any function or tool to handle this error?
Filter on IsNumeric:
SELECT line, CCur([data]) AS data
FROM Input
WHERE IsNumeric([data])
Note that this will still throw errors internally, it just doesn't return them. This can be a problem in certain situations (e.g. when using VBA to open a recordset). We can avoid that using IIF:
SELECT line, CCur(Iif(IsNumeric([data]), [data], 0)) AS data
FROM Input
WHERE IsNumeric([data])
I have the following query in access where i want to compare a text column value to a combo value
SELECT NAME.ID, NAME.V_name, NAME.Gender, NAME.V_center, NAME.BoxNo, NAME.SerinBox
FROM NAME
WHERE ((cint([Forms]![Name]![Combo75].value) >= 2020-cint(left([name.id])))
and (cint([Forms]![Name]![Combo77].value) <= 2020-cint(left([name.id]))));
getting error in SQL statement, couldn't figure it out.
Image of error
The error is pretty clear:
Wrong number of arguments . . .
The code in question is:
left([name.id])
The left() function takes two arguments. The second is how many characters to return.
I am looking for a function which can help me to query multiple input values on a particular column which stored as an array
Already tried using like function to search in a string
select *
from express_dwh.kengic_bag_seal_ad_json
where Sorter_id='KENGIC_1' and ad >='2019-08-21-0' and
wbns LIKE '%3008127238325%' OR wbns LIKE '%3008127259896%' OR wbns LIKE '%3008127263750%'
Error running query:
SYNTAX_ERROR: line 3:56: Left side of LIKE expression must evaluate to a varchar (actual: array(varchar))
You might be looking for the “overlaps” operator &&:
wbns && ARRAY[3008127238325,3008127259896,3008127263750]
Depending on the data type, you may need a cast like
wbns && ARRAY[3008127238325,3008127259896,3008127263750]::numeric[]
I'm trying to load some data from stage to relational environment and something is happening I can't figure out.
I'm trying to run the following query:
SELECT
CAST(SPLIT_PART(some_field,'_',2) AS BIGINT) cmt_par
FROM
public.some_table;
The some_field is a column that has data with two numbers joined by an underscore like this:
some_field -> 38972691802309_48937927428392
And I'm trying to get the second part.
That said, here is the error I'm getting:
[Amazon](500310) Invalid operation: Invalid digit, Value '1', Pos 0,
Type: Long
Details:
-----------------------------------------------
error: Invalid digit, Value '1', Pos 0, Type: Long
code: 1207
context:
query: 1097254
location: :0
process: query0_99 [pid=0]
-----------------------------------------------;
Execution time: 2.61s
Statement 1 of 1 finished
1 statement failed.
It's literally saying some numbers are not valid digits. I've already tried to get the exactly data which is throwing the error and it appears to be a normal field like I was expecting. It happens even if I throw out NULL fields.
I thought it would be an encoding error, but I've not found any references to solve that.
Anyone has any idea?
Thanks everybody.
I just ran into this problem and did some digging. Seems like the error Value '1' is the misleading part, and the problem is actually that these fields are just not valid as numeric.
In my case they were empty strings. I found the solution to my problem in this blogpost, which is essentially to find any fields that aren't numeric, and fill them with null before casting.
select cast(colname as integer) from
(select
case when colname ~ '^[0-9]+$' then colname
else null
end as colname
from tablename);
Bottom line: this Redshift error is completely confusing and really needs to be fixed.
When you are using a Glue job to upsert data from any data source to Redshift:
Glue will rearrange the data then copy which can cause this issue. This happened to me even after using apply-mapping.
In my case, the datatype was not an issue at all. In the source they were typecast to exactly match the fields in Redshift.
Glue was rearranging the columns by the alphabetical order of column names then copying the data into Redshift table (which will
obviously throw an error because my first column is an ID Key, not
like the other string column).
To fix the issue, I used a SQL query within Glue to run a select command with the correct order of the columns in the table..
It's weird why Glue did that even after using apply-mapping, but the work-around I used helped.
For example: source table has fields ID|EMAIL|NAME with values 1|abcd#gmail.com|abcd and target table has fields ID|EMAIL|NAME But when Glue is upserting the data, it is rearranging the data by their column names before writing. Glue is trying to write abcd#gmail.com|1|abcd in ID|EMAIL|NAME. This is throwing an error because ID is expecting a int value, EMAIL is expecting a string. I did a SQL query transform using the query "SELECT ID, EMAIL, NAME FROM data" to rearrange the columns before writing the data.
Hmmm. I would start by investigating the problem. Are there any non-digit characters?
SELECT some_field
FROM public.some_table
WHERE SPLIT_PART(some_field, '_', 2) ~ '[^0-9]';
Is the value too long for a bigint?
SELECT some_field
FROM public.some_table
WHERE LEN(SPLIT_PART(some_field, '_', 2)) > 27
If you need more than 27 digits of precision, consider a decimal rather than bigint.
If you get error message like “Invalid digit, Value ‘O’, Pos 0, Type: Integer” try executing your copy command by eliminating the header row. Use IGNOREHEADER parameter in your copy command to ignore the first line of the data file.
So the COPY command will look like below:
COPY orders FROM 's3://sourcedatainorig/order.txt' credentials 'aws_access_key_id=<your access key id>;aws_secret_access_key=<your secret key>' delimiter '\t' IGNOREHEADER 1;
For my Redshift SQL, I had to wrap my columns with Cast(col As Datatype) to make this error go away.
For example, setting my columns datatype to Char with a specific length worked:
Cast(COLUMN1 As Char(xx)) = Cast(COLUMN2 As Char(xxx))
An old dbf have been succesfully ODBC-connected to Excel (2010). The following SQL query (through Microsoft Query) works as expected giving a single result.
Microsoft Query (Excel 2010) code
SELECT c.NDELNUM AS deliverynote, SUM(c.NQTY*a.CPREDEF2) AS Total
FROM DelCusL AS c, Article AS a
WHERE c.CREF = a.CREF AND ((c.NDELNUM=?))
GROUP BY c.NDELNUM
I am interested in getting also single value, but the following retuns NULL:
SELECT c.NDELNUM AS deliverynote, SUM(c.NQTY*(a.CPREDEF2+c.CPROP2)) AS Total
FROM DelCusL AS c, Article AS a
WHERE c.CREF = a.CREF AND ((c.NDELNUM=?))
GROUP BY c.NDELNUM
I guess this does not work because empty values are encountered in either a.CPREDEF2 or c.CPROP2. When an empty value is encounterd, I'd like it to be treated as 0. I have tried casting value functions available in Microsoft Query to not much avail.
Any idea on converting EMPTY values to 0s so that the operation is successful?
NQTY is a number and always non-empty. CPREDEF2 is treated as VARCHAR and can be EMPTY: when EMPTY it seems to be treated as NULL from other tests; CPROP2 is an alternative value to CPREDEF2 and can also be EMPTY, if filled it can be understood as number(like CPREDEF2). Both CPREDEF and CPROP2 are treated as VARCHAR rather than numerical values but when on their own are correctly multiplied and aggregated as numbers. (It fails when I try to add them together before the aggregate function).
Try to CAST before you add the values:
... * (CAST(a.CPREDEF2 AS DECIMAL(10,5))+CAST(c.CPROP2 AS DECIMAL(10,5))) ...