Compare dates using Dateserial in Access 2007 SQL - sql

I have the following SQL
SELECT P1.Column1, P1.NextApprovalDate
FROM Procedures P1
WHERE DATESERIAL(YEAR(P1.NextApprovalDate), MONTH(P1.NextApprovalDate), 1 )
= DATESERIAL(YEAR(Date()), MONTH(DATE()) + 1, 1);
I get an error which is "Data type mismatch in criteria expression". I tried using the CDate and the Format functions in conjunction as well but continue to get the same error. The SQL runs fine when I am selecting the criteria there. How should the criteria be formatted?

Ok. I got this to work but it is kind of weird the way Access wanted it. The = sign never worked for the comparison. Why I don't know. The BETWEEN worked. If someone could find a way to make the '=' work, do let me know. Thanks to #Hansup for pointing me in the right direction.
SELECT P2.Column1, P2.NextApprovalDate
FROM (SELECT Procedures.Column1, Procedures.NextApprovalDate FROM
Procedures WHERE Procedures.NextApprovalDate IS NOT NULL) AS P2
WHERE DATESERIAL(YEAR(P2.NextApprovalDate),MONTH(P2.NextApprovalDate),1)
Between DATESERIAL(YEAR(Date()),MONTH(Date())+1,1) And
DATESERIAL(YEAR(Date()),MONTH(Date())+1,1);

Related

Access 2007 CInt Query Issue

There is probably a pretty basic answer to this question, but I'm pulling my hair out trying to resolve my issue. I'm using Access 2007.
My query is shown below:
SELECT Pricing.*
FROM OrderReceipt_be
INNER JOIN Pricing ON CInt(OrderReceipt_be.[Pricing Table Option Code]) = Pricing.ID
WHERE OrderReceipt_be.[PO_Number] = PONumber();
For whatever reason, the [PO_Number] field is stored as text against my key which is a long int. This is why I'm trying to convert it to an integer.
However, when I run my query I get the error
"Compile error. in query expression CInt(OrderReceipt_be.[Pricing
Table Option Code]) = Pricing.ID".
I've done some basic research and it seems like the most common issue is that I'm missing a reference library. Howver, having gone through the entire list, I don't see any references that are tagged as "Missing" so it must be something else. I've also tried disabling and re-enabling all enabled reference libraries to see if that helps, but so far nothing.
Any thoughts?
If you can have codes of Null, try:
SELECT Pricing.*
FROM OrderReceipt_be
INNER JOIN Pricing ON Val(Nz(OrderReceipt_be.[Pricing Table Option Code])) = Pricing.ID
WHERE OrderReceipt_be.[PO_Number] = PONumber();
or try the reverse conversion:
SELECT Pricing.*
FROM OrderReceipt_be
INNER JOIN Pricing ON OrderReceipt_be.[Pricing Table Option Code] = CStr(Pricing.ID)
WHERE OrderReceipt_be.[PO_Number] = PONumber();

VB.NET - LINQ - dbContext - Where - Letter is not declared error. Trying to update single record

I'm in the process of writing an update code to update user information on an asset used for a project I have. The code is below...
AlteredUser = dbContext.Assets.Where(c >= c.ParentAssetID = ParentAssetId And c.AssetDecription = "USER").SingleOrDefault()
AlteredUser.AssetName = UserName
dbContext.SubmitChanges()
I'm getting an error message saying " 'c' is not declared ". I've seen several examples of how to use the where clause within dbContext, and all of them use a letter as LINQ normally does. I cannot figure out why it is erroring out for me.
Any help would be greatly appreciated.
Thank you!
>= is a comparison operator.
To create a lambda in VB, write
Function(c) c....

Adding an error message to return. SQL Server

Well, I'm trying to construct some error reporting.
Current snippet of code, which will put into a stored procedure after I get this code correct...
begin
select *
from dbo.DIM_S17_Detail
Where ((LEN(New_Acc_Flag) >1 or ISNUMERIC (Substring(New_Acc_flag, 1, 1)) = 1))
end
So, the defined datatype is either a Y/N - Alphanumeric, so it picks out ISNUMERIC as 1, so it will bring up the selected records which ARE numeric - so these records are incorrect...
I hope you still follow...
So, if a 'New_Acc_Flag' is TRUE, it will bring up those record(s) and should return a message something like "Y/N not selected" or "Y/N Value only".
Thanks again.
Please bear in mind I'm a noobie to SQL.
If I understand what you want correctly you can use THROW or RAISERROR

error deleting content that matches the result of a Select in ODBC

I am working with an ODBC driver, and I am trying to delete some old comments from a database. I am getting this error and I don't know why. All those tables exist and are accessible by me.
DELETE FROM [Z_TEST_pnt.pnt_comment_record]
WHERE [Z_TEST_pnt.pnt_comment_record].[L2Key] IN
(SELECT POINT.QueueKey FROM [Z_TEST_pnt.pnt_header_record] AS POINT
WHERE (datediff(day, POINT.last_update_time, NOW()) > 7))
I get the error:
[ODBC EOP driver][OpenAccess SDK SQL Engine]Base table:Z_TEST_pnt.pnt_header_record not found.[10129]
I appreciate any suggestions. Thank you.
Found it! I just needed to remove the brackets from the table names. I added them in the first place because I was having an error running that query from VBS, and I thought that the error was that I couldn't have a name with more than one dot on it.
This code works:
DELETE FROM Z_TEST_pnt.pnt_comment_record
WHERE Z_TEST_pnt.pnt_comment_record.[L2Key] IN
(SELECT POINT.QueueKey
FROM Z_TEST_pnt.pnt_header_record AS POINT
WHERE (datediff(day, POINT.last_update_time, NOW()) > 7))

Access SQL for sorting by date with TempVars

im trying to make a query from the use of TempVars
im Using SQL to run the query but every time i try, it return Invalid date value
this is the line that will not work
this returns error
WHERE ((([Table].[Issue Date])>=#[TempVars]![tmpDateFrom]# And ([Table].[Issue Date])>=#[TempVars]![tmpDateTo]#));
this returns fine
WHERE ((([Table].[Issue Date])>=#10/12/12# And ([Table].[Issue Date])>=#11/12/12#));
I have checked the TempVars [tmpDateFrom] and [tmpDateTo] and they out put the date value i need.
Please help
Thank you all or the help.
due to the requirement of the database #Nicarus had the right answer this is the solution for those still wondering.
WHERE ((([Table].[Issue Date])>=[TempVars]![tmpDateFrom] And ([Table].[Issue Date])>=[TempVars]![tmpDateTo]));