Too Few Parameters Expected 1-MS Access error - ms-access

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)

Related

How to convert date from csv file into integer

I have to send data from csv into SQL DB.
Problem starts when I try to convert data into Int. It wasnt my idea and I really cant do much with this datatype. When I'm trying to achieve this problem pop up:
Data Conversion 2: Data conversion failed while converting column
"pr_czas" (387) to column "C pr_dCz_id" (14). The conversion returned
status value 2 and status text "The value could not be converted
because of a potential loss of data.".
Tried already to ignore this problem but then another problems came up so there is no other way than solving this.
I have to convert this data from csv file which is str 50 into int 4
It must be int4. One of the requirements Dont know what t odo.
This is data I'm trying to put into int4. Look on pr_czas
This is data's datatype
Before I tried to do same thing with just DD.MM.YYYY but got same result...
Given an input column named [pr_czas] that contain string values that look like 31.01.2020 00:00 which appears to be a formatted date time represented in the format "DD.mm.YYYY HH:MM", I would like to express that as a whole number DDMMYYHHMM
Add a derived column to your data flow and call this new_pr_czas
The logic I'm going to use is a series of REPLACE statements and cast the final result to an integer. Replace the period, replace the colon and the space - all with nothing
(DT_I8)REPLACE(REPLACE(REPLACE([pr_czas], ".", ""), ":", ""), " ", "")
This is an easy case but things to note.
An integer/int32/I4 has a maximum value of 2 billion.
310120200000 is too large to fit into that space so you would need to make that an bigint/int64/I8. If I remember your previous question, you were having troubles with a lookup task so this data type mismatch might hurt you there.
The other thing to be aware of is that leading zeros will be dropped when converted to a number because they are not significant. If you need to retain the leading zeros, then you're working with string data type. This is an advantage to working with the ISO standard but if your data expects DD, then far be it for me to say otherwise.
If you need to slice your date into another format, then you'll want to have a few derived columns. The first one will generate a string column for each piece of pr_czas - year, month, day, hour and minute. You'll use the substring method for this and findstring to find the period space and colon.
The next data flow will be used to put those string pieces back into the new format and cast that to I8. Why? Because you can't debug doing it all in one shot but you can put a data viewer between two derived columns to figure out where a slice went awry.

Syntax error in date in query expression for non-date fields

I'm having trouble building a query in Access 2013. The database isn't mine and the only thing I really have control over is this query. There is a table, I'm pulling 7 fields from it and eventually adding an 8th field to the query to do some string manipulation.
However, I keep getting getting "Syntax error in date in query expression 'fieldname'." error whenever I click on the arrow to sort the fields. The odd thing is these errors pop up when sorting non-date fields. When sorting the date field I get "Syntax error (missing operator) in query expression 'Release Date'."
This happens after a fresh build. I have no WHERE conditions, just SELECT and FROM. Ideas?
Here's the sql query, though I'm mainly working in the query design view:
SELECT Transmissions.[Job#], Transmissions.[Part#], Transmissions.TransmissionSN, Transmissions.Status, Transmissions.[Release Date], Transmissions.[Build Book Printed], Transmissions.[ID Tags Required]
FROM Transmissions;
Well... it seems you are the lucky inheritor of a poorly designed database.
Using special characters in a field name is just asking for trouble. And you've found what that trouble is.
Access uses the # sign to designate a Date type for query comparisons. Such as:
dtSomeDate = #2/20/2017#
You surround the date with the # signs.
In your case, the query thinks [Job#] and [Part#] are trying to wrap dates. But of course, that's not the case and thus it fails.
You can try a couple of work arounds. (I leave it to you to experiment.)
1) You can try to rename the problem fields within your query. So that:
Transmissions.[Job#] becomes Transmissions.[Job#] as JobNum
and
Transmissions.[Part#] becomes Transmissions.[Part#] as PartNum
2) You can try to copy the [Transmissions] table to a new table that you create
that does not have the naming problems.
3) Export the [Transmissions] table to a CSV file and re-import it to a new
table (or possibly new database) without the naming problems.
Here is a link to a microsoft article that tells you why to avoid special characters in Access:
Big Bad Special Chars.
Hope that puts you on the right track. :)
Typically, this means that the field names are missing or misspelled.
Try running this to see:
SELECT * FROM Transmissions;

ms access ascii conversion unable to filter

I'm using the "ASC" function in Access (Version 365 Proplus, 32 bit).
Have created a query that uses a table with a post code that needs validating. I'm looking at the first character in the postcode, converting it to ASCII character then planning on filtering out the ones I don't want.
The formula looks like this:-
Site_PostCode_String_Validation_P1: Asc(Left([site_postcode],1))
This works fine and converts as expected. However, when I try sorting or filtering using the Query Criteria on my Ascii list I get the following message:-
"Data Type Mismatch in Criteria Expression"
I have tried converting to a string, for example, using the below:-
Str(Asc(Left([site_postcode],1)))
But this has made no difference, get the same error message when applying criteria or sorting.
I have tried filtering using text and numbers but get the same error.
I have searched here and have Googled but can not see anything relating to the above.
Thanks for any suggestions.
You might simplify it a bit:
Site_PostCode_String_Validation_P1: Asc(Nz([site_postcode], Chr(0))
I tried creating a new table based on the results, thinking that this would then enable me to apply my filtering, during this process I got a more detailed error message stating error due to Null type conversion failure. So then realized that I need to make sure there were no Null entries before doing the ascii conversion. Hopefully this will be of help to someone else. Final formula now works as below:
IIf(IsNull([site_postcode])=-1,Null,Asc(Left([site_postcode],1)))

MySQL define 1 result as text from SELECT query

Using: MySQL Workbench & MySQL for Excel
I have a number returned that is 12 digits long, however when imported in to excel using any manner this results in: 1.20523E+11.
I want (need) to specify that the value needs to be returned as text so to complete the query via MySQL for Excel without this error.
My existing query:
Select
-- Get Order data --
T5.orders_id As OID,
DATE_FORMAT(T5.date_purchased, '%Y-%m-%d') As ODate,
T3.products_name As PName,
T3.products_id As PID,
error:
DATE_FORMAT(T5.date_purchased,'%y%m%d%H%i%s') As DecRepID,
-- This results in 1503070244
-- Transaction ID to match with Payments
I need the 1503070244 to return as TEXT so excel imports it without me needing to then convert the text.
I've looked at CONVERT & CAST however I can't get the query to work correctly & they resolve in to syntax errors.
CONVERT(VARCHAR(12),(DATE_FORMAT(T5.date_purchased,'%y%m%d%H%i%s'))) As DecRepID,
CAST returns the correct values, however Excel doesn't recognise as text.
cast(DATE_FORMAT(T5.date_purchased,'%y%m%d%H%i%s') as char) As DecRepID
I know it's something simple, however I can't find what is the cause of the error.
Is there a way to correct this through code, or am I stuck with post-formatting after import in to Excel?
Thank you.
Using the idea that Shahkalpesh had, you could do 2 different things:
1) You could try escaping the ' by using: '\''
concat('\'', DATE_FORMAT(T5.date_purchased,'%y%m%d%H%i%s')) As DecRepID,
2) You could try escaping the ' by using: "'"
concat("'", DATE_FORMAT(T5.date_purchased,'%y%m%d%H%i%s')) As DecRepID,
By escaping the ' the column will import in to Excel as: '1503070244 which is what you will need to have Excel recognise it as text to stop the shortened result.
You can read more here: http://dev.mysql.com/doc/refman/5.7/en/string-literals.html

Why my date is written 0000-00-00

I have a table where the date column name is defined as proddate and defined as DATE.
Here is the code I write the value into table:
cmd.Parameters.Add("#Mydate", MySqlDbType.DateTime).Value = Convert.ToDateTime(MyArray[4]).ToString();
This gives a result of 0000-00-00
When I change it to
cmd.Parameters.Add("#Mydate", MySqlDbType.DateTime).Value = Convert.ToDateTime(MyArray[4]);
The result is correct. eg: 2013-11-14
However few lines down I have this code
cmd1.Parameters.Add("#date", MySqlDbType.DateTime).Value = Convert.ToDateTime(MyArray[4].ToString());
This gives no error. I get the correct result in table
And few lines after I have this code in the same method:
cmd3.Parameters.Add("#Mydate", MySqlDbType.DateTime).Value = MyArray[4].ToString();
This gives no error too
The last two lines I did the mistake for testing. But the columns of 2 last exemples are defined as DATE format
Any idea ? Or Am I welcome in the mystery world of Mysql ?
PS: I use MYSQL CONNECTOR 6.7.4.0 .NET3.5 and C# 2008 Express. In my server MYSQL is 5.0
In the first version, you're converting your value to a DateTime and then to a string, using the default format for a DateTime value. MySQL is then trying to parse that, and presumably failing.
In the second version, you're parsing your value as a DateTime, and supplying it to MySQL directly. This is the best approach, although you need to be careful about the input format you're using.
The third version is like the second, just with an explicit ToString call. If MyArray is of type string[], that's basically a no-op.
The fourth version is providing the string input directly to MySQL, which is presumably able to parse it itself. I would suggest avoiding that form though - parse it in the .NET code, where you have much more control.