MONTH IN MS ACCESS - ms-access

When executing the code , Datatype mismatch Error is showing .Can tell if i need only Month(either as January,February.. or as 1 ,2,...12) as a field in MS Access database what should i give as data type.
Thanks for your answer.One more query:
if (rs6("TotalDays")+ tdays) > rs5("Sing") then
Is there any syntax error in this statement..?
tdays holds the number.

Month() in access takes a parameter of type DateTime and returns the number of the month. To get the month name, you could either do FormatDate(Month(yourDate), 'mmmm') or MontName(yourDate) (in Access 2000 and later).
See here for more info.

Related

SQL Openquery - Object has no columns

I have a dynamically Stored Procedure, which creates an mdx statement for an OpenQuery. So it can happen that the objects from the mdx statement are empty. In this case I want back an empty string.
Generally, the query works except when I choose a date that is from the future in which case the SQL Server gives me this error:
"The OLE DB provider "XYZ" for linked server "XYZ" indicates that
either the object has no columns or the current user does not have
permissions on that object."
select
t.*
from OPENQUERY([SomeServer_OLAP],''
SELECT
non empty{[Measures].[FactWorkItemHistory Microsoft_VSTS_Scheduling_OriginalEstimate],
[Measures].[FactWorkItemHistory Microsoft_VSTS_Scheduling_CompletedWork],
[Measures].[Microsoft_VSTS_Scheduling_RemainingWork]} ON COLUMNS
, NON EMPTY { ([Work Item].[Iteration Path].[Iteration Path].ALLMEMBERS
* [Work Item].[System_AssignedTo].[System_AssignedTo].ALLMEMBERS)} on ROWS
FROM [Team System]
WHERE '+#Month+'
'') t'
So, entering the date parameter for December (the month of writing this post) works fine, but entering January of 2018 (next month) and all the other following months returns the error. Any help is appreciated.
Removing "non empty" from the query fixed my issue. There doesn't seems to be any immediate observable drawbacks to this.

Access Report - Calculating Hours between 2 times

I have a SQL time off database with a Access front end. I currently have BeginTimeOff and EndTimeOff fields on the report. In my SQL database, these are Time(7) fields. I want a new field to show the time difference. I've tried to have the Control Source be equal to:
=DateDiff("n",CDate([BeginTimeOff]),CDate([EndTimeOff]))
AND
=DateDiff("n",[BeginTimeOff],[EndTimeOff])
AND
= [EndTimeOff] - [BeginTimeOff]
I can't get anything to work. I can subtract dates fine, just not times. Help!
Access does not have a time-only field type (Access Date/Time fields have both a date and time component), and any unknown field types in an ODBC linked table are usually mapped to Text. So if you have a SQL Server table with time(7) columns ...
CREATE TABLE [dbo].[TimeTest](
[Id] [int] NOT NULL,
[BeginTimeOff] [time](7) NULL,
[EndTimeOff] [time](7) NULL
...
then the corresponding ODBC linked table in Access will have Text(255) columns instead:
If you want to directly use the columns in the linked table then you will have to convert the values into a form that Access will accept before you can use functions like DateDiff() to do calculations with them. Specifically, Access Date/Time values do not support fractional seconds so you will have to remove them. That is,
CDate("07:59:00.0000000")
will fail with a "Type mismatch" error (run-time error 13), while
CDate("07:59:00")
works fine. You can use string manipulation functions like InStr(), Left(), Mid(), etc. to get rid of the fractional part of the string.
Another approach would be to create a SQL Server View that converts the DATE(7) columns to DATETIME
CREATE VIEW [dbo].[TimeView]
AS
SELECT
Id,
DATEADD(day, -2, CONVERT(DATETIME, BeginTimeOff)) AS BeginTimeOff,
DATEADD(day, -2, CONVERT(DATETIME, EndTimeOff)) AS EndTimeOff
FROM dbo.TimeTest
and then if you link to that View the columns will appear as Date/Time values in Access

Using BIDS to extract data from Informix ODBC source with parameters

As it says in the title, I am trying to extract data from my Informix ODBC source with parameters. I have two parameters that i am trying to pass. Both are DateTime and i am trying to get the current starting date for example 2014-10-10 00:00:00 and the ending date 2014-10-10 23:59:59.
If i do this with a normal query:
SELECT * FROM TABLENAME
WHERE STARTDATETIME BETWEEN '2014-10-10 00:00:00' AND '2014-10-10 23:59:59'
Everything works fine. However, if I try and use the parameters that I have set up:
SELECT * FROM TABLENAME
WHERE STARTDATETIME BETWEEN ? AND ?
I get the following error:
Open Database Connectivity (ODBC) error occurred. state: '07001'.
Native Error Code: -11012. [Informix][Informix ODBC Driver]Wrong number of parameters.
I feel like it has to do with my query, but I have been looking and have found nothing. Would anyone be able to help me out? Thanks!
When you use parameterized query ('?') binding is needed.
Likely you may be using ODBC API SQLBindCol for binding it.
The number of parameter in the query (in this case it is 2)
should be matching with number of bind API calls.
Please check your ODBC code to make sure the binding is correctly done.

DST to UTC append query creates a type conversion error in access

I have a table I'm using as a source for an append query that calls upon a table query, which calls upon a union query to effectively adjust the eastern prevailing time to spring forward and fall back while converting to utc. there are only three fields in the table but I keep getting "access did not import .... due to type conversion". Please Help Me out!!! Thank you in advance
below is the access sql:
{append query}
INSERT INTO somePrice ( price )
SELECT DTQuery.Price
FROM DTQuery
WHERE (((DTQuery.EPT)<>[2ndsunday]));
{DTQuery}
SELECT
TransposeQuery.Field3 AS [Zone]
, DateSerial(Left([field1],4),Left(Right([field1],4),2),Right([field1],2))+[TransposeQuery]![Hour]/24 AS EPT, Val([Field8]) AS Price
, DateValue(DateSerial(Year([EPT]),3,14))-(Weekday(DateValue(DateSerial(Year([EPT]),3,14)),1)-1)+3/24 AS 2ndSunday
, DateValue(DateSerial(Year([EPT]),11,7))-(Weekday(DateValue(DateSerial(Year([EPT]),11,7)),1)-1)+3/24 AS 1stSunday
FROM TransposeQuery
ORDER BY
TransposeQuery.Field3
, DateSerial(Left([field1],4),Left(Right([field1],4),2),Right([field1],2))+[TransposeQuery]![Hour]/24, Val([Field8]);
First some general stuff: If you want to convert between timezones, which involves adding or subtracting a number of hours you might want to use to DateAdd function.
DateAdd("h", -2, [SourceDateTime])
This simply takes two hours off the SourceDateTime field.
Also rather than using the Left(Right( combination you can use Mid(string, start, length)
Mid("1234567890", 2, 4)
Returns 2345, but if you are dealing with dates just use DatePart
DatePart("h", "17/12/2011 08:10")
Returns 8.
As for the type conversion error, it's hard to say as you haven't given us the types of the fields in the destination table.
If you run the append query without the first line this will rule out the destination table. If it still fails then it might be in the where clause, so move the fields into the results set and make sure they are the same type. If it still fails then it must be in the source query so check DTQuery opens without any problems.

SSIS (2008R2) import from mssql to mysql failing due to a date column

I have an oledb connection to mssql and an ado.net destination (with odbc driver used) to mysql. The tables are exectly the same and all the columns are working bar one.
The error message received is:
[ADO NET Destination [325]] Error: An exception has occurred during data insertion, the message returned from the provider is: Unable to cast object of type 'System.DateTime' to type 'System.Char[]'.
I've seen similar questions on other data types but the resolution of changing to string does not work here. If I convert to string (has to be length 29 otherwise the conversion step fails) I get the following error message:
[ADO NET Destination [325]] Error: An exception has occurred during data insertion, the message returned from the provider is: ERROR [HY000] [MySQL][ODBC 5.1 Driver][mysqld-5.5.15]Incorrect datetime value: '2011-03-21 11:23:48.573000000' for column 'LastModificationDate' at row 1
Other potentially relevant details:
connection driver- {MySQL ODBC 5.1 Driver}
script run before dataflow - set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES'
Other datetime columns are working
This column has a reasonably high proportion of nulls
mssql spec: [LastModificationDate] [datetime] NULL
mysql spec: LastModificationDate datetime NULL
Has anyone had experience with this issue and could provide some advice on resolving it?
Can you try converting it to string on sql server side in your query using:
convert(char(10),LastModificationDate,111)+' '+convert(char(8),LastModificationDate,108)
This works for me all the time.
I got the same big headache this week. I tried many ways. Thanks God, finnally, one of them worked. Hope it could help you a little bit.
For some columns with the data type of Int, datetime, decimal....,here, I identified as ColumnA, and I used it as datetime type.
1.in Data Flow Source, use SQL Command to retrieve data. Sth like select isnull(ColumnA,'1800-01-01') as ColumnA, C1, C2, ... Cn from Table
Make sure to use Isnull function for all columns with the datatype mentioned before.
2.Excute the SSIS pkg. It should work.
3.Go back to Control Flow, under the data flow task, add SQL Task control to replace the data back. I mean, update the ColumnA from '1800-01-01' to null again.
That works for me. In my situation, I cannot use ignore failure option. Because if I do, I will lose thousands rows of data.