Ms Access Error - The field is too small to accept the amount of data you attempted to add - sql

I am trying to build a select query in ms access, however am getting the error message: "The field is too small to accept the amount of data you attempted to add."
The sql is :
SELECT ProjectList.ProjectID, UpcomingOpenMilestone.MinOfPlannedDate,
UpcomingOpenMilestone.FirstOfMilestone
FROM UpcomingOpenMilestone RIGHT JOIN ProjectList ON
UpcomingOpenMilestone.ProjectID = ProjectList.ProjectID;
The query is pulling from one other query and a table. The ProjectList.ProjectID field is an autonumber field.
The UpcomingOpenMilestone qry is generated from one table and the sql is as follows:
SELECT MilestoneTracking.ProjectID, Min(MilestoneTracking.PlannedDate) AS
MinOfPlannedDate, First(MilestoneTracking.Milestone) AS FirstOfMilestone
FROM MilestoneTracking
GROUP BY MilestoneTracking.ProjectID, MilestoneTracking.ActualDate
HAVING (((MilestoneTracking.ActualDate) Is Null));
The ProjectID is the foreign key, therefore number type field, Milestone is a short text and limited to 200 characters and then PlannedDate and ActualDate are both date type fields.
I don't understand why the field would be too small, I've tried limiting the query that is generating the error to only try and pull in the ProjectID or other single fields however it does not work. The only way that it will run is if I drop the Right Join.
Any help is appreciated!

Related

Access 16 append query - Syntax error (missing operator) in query expression WHERE clause

I am still not too experienced with access, SQL, VBA and this is my first post. So please go easy on me! Okay lets get to it. I have been updating an access file due to irrelevant and duplicate records showing up on reports.
First I was having trouble appending records due to Key violations that I determined was due to appending to primary key fields, which I remedied by creating an autonumber ID Primary key on the destination table. I am having trouble updating the query with a WHERE clause to not add records already on the destination table. Field and table names have been changed below, but I am trying to insert into "dandy" from "bag" and "rug".
Error message reads:
Syntax error (missing operator) in query expression '"NOOB"
WHERE [rug].[TENT] AND [rug].[CANDY] NOT IN (SELECT [TENT] AND [CANDY] FROM [dandy])'.
See SQL Code below:
INSERT INTO dandy(CANDY, FUN, DOG, TREAT, BUMPY, TENT, System )
SELECT Val([CANDY]) AS Burger,
Val([FUN]) AS FUN_VAL,
rug.STOVE,
rug.TREAT,
IIf([Bag]![Water] Is Not Null,[Bag]![Water],[rug]![BUMPY]) AS BUMPY,
rug.TENT,
"NOOB" AS System
FROM rug
INNER JOIN [crib] ON rug.CANDY= [crib].Dip)
INNER JOIN Bag ON ([crib].FacNum = Bag.[Trip]) AND (rug.TENT = Bag.Lip)
GROUP BY
Val([CANDY]),
Val([FUN]),
[rug].STOVE,
[rug].TREAT,
IIf([Bag]![Water] Is Not Null,
[Bag]![Water]
[rug]![BUMPY]),
rug.TENT,
"NOOB"
WHERE [rug].[TENT] AND [rug].[CANDY] NOT IN (SELECT [TENT] AND [CANDY] FROM [dandy])
HAVING (((IIf([Bag]![Water] Is Not Null,
[Bag]![Water],
[rug]![BUMPY])) Is Null));
If you want to prevent duplicate pairs of Tent and Candy in table, just set a compound Index in table with those two fields. Records that would cause duplication will be rejected. The IN() criteria can be eliminated.
As for the IN() criteria, I tested your original syntax. It does not error but also does not retrieve records. Splitting into two NOT IN() expressions also failed - no records met the AND condition.
WHERE TENT NOT IN (SELECT TENT FROM dandy) AND CANDY NOT IN (SELECT CANDY FROM dandy)
However, concatenation did retrieve correct records.
SELECT * FROM datasource
WHERE TENT & CANDY NOT IN (SELECT TENT & CANDY FROM dandy)

Accsss SQL query using a "where" clause to link on memo field (long text) but Access is droping records

I am trying to join a table and a query on a long text field in MS Access. As Access prevents such a join, I am using a Where clause as a workaround. The issue is that I am losing 80ish less records in the query's result as expected although the query is otherwise producing the results I want/need. I am simply unable to see what the issue is. Thank you so much for your help.
Query 1: q_Responses_Question1Through7_IntermediateStep3, (#Records=784) Structure:
Field 1: Name=ID, Primary Key, Type=AutoNumber
Field 2: Name=Question7, Type=Long Text, No null values
Table 1: t_LookUp_Question7_Responses (#Records=657) Structure:
Field 1: Name=Q7_ID, Primary Key, Type=AutoNumber
Field 2: Name=Description, Type=Long Text
MS Access SQL Query (#Results 695):
SELECT A.ID, B.Q7_ID
FROM q_Responses_Question1Through7_IntermediateStep3 AS A, t_LookUp_Question7_Responses AS B
WHERE (A.Question7=B.Description);

Why The Query Against HashKey returns no records

I am working on a new sql table. The table has a column [varbinary(8000)], where we are storing hash of a certain text. Now, I am trying to retrieve the same record back by using a where clause against the hashkey, but that yields zero records.
I have added a similar query here: http://sqlfiddle.com/#!18/be996/11
Try without the single quotes, like this
SELECT id, description
FROM ForgeRock
where id = 0x94EE059335E587E501CC4BF90613E0814F00A7B08BC7C648FD865A2AF6A22CC2
and you will get the expected result.

How can I pull off an INSERT, SELECT, JOIN, and CAST query with Microsoft SQL Server Management Studio?

I have been trying to set up a test database but I keep running into issues with pulling in the data from its normalized form.
Below is the latest version of the SQL query I've been working on.
INSERT INTO TestData.dbo.Info (Name,Did)
SELECT DISTINCT a.Name, b.Did
FROM StageDB.dbo.MockData a INNER JOIN Testdata.dbo.Dinfo b
ON a.Name = CAST(b.Did as varchar(10))
The output I get is the following:
(0 row(s) affected)
I've been trying to monkey around with it on my own but can't seem to make it work the way I want to.
My objective here is to pull data (the primary key from a table with data already in my database, Did from TestData.dbo.Dinfo that is of int type) and merge it with data from my staging table (a particular column from the table in the staging database, StageDB.dbo.MockData, Name of type varchar(10)), then inserting into a new table on my main database. The database table I'm trying to put these things into is all set up with the correct fields and types (primary key column, auto generated as rows are added, Name column that is varchar(10), and Did column that is int).
EDIT: Table Definitions, Sample Data, Desired Result
Destination Table:
TestData.dbo.Info
Columns: Iid (int, primary key of table set to auto increment as new records are added), Name (varchar(10)), Did (int, foreign key from TestData.dbo.Dinfo).
StageDB.dbo.MockData
Columns: Many columns exist in this table that are not relevant to what I am trying to pull off. The only one I am interested in is the column containing names that I want to tie together with information from the Dinfo table. Name (nvarchar(255),null).
TestData.dbo.Dinfo
Columns: Did (int, primary key), Donor (varchar(20)).
Sample of Data
From Dinfo:
Did Donor
01 Howard L
From MockData:
Name
Smith J
Desired Results
Iid Name Did
01 Smith J 01
Any help or advice would be much appreciated. I would really like it if someone can show me the correct SQL syntax for this as I think it may just be a matter of writing it correctly. Additionally, any tips or websites that can help me learn more SQL would be appreciated.
Thank you!
Change this:
ON a.Name = b.Did
To this:
ON a.Name = CAST(b.Did as varchar(10))
I suspect there's a lot more wrong with your query in terms of getting the results you want, but this should fix your error.
You need to figure out where the error is occurring. There are three possibilities:
mockdata.name is a string and NInfo.data is an integer
dinfo.did is a string and NInfo.did is an integer
mockdata.name is a string and dinfo.did is an integer (or vice versa)
Based on the naming conventions, the third is the most likely. When a number is compared to a string, the string is converted to a number. However, you need to be careful whenever you use implicit type conversions.
If the third option, then you can convert the integer to a string (as other answers propose). However, I would ask why you are doing such a comparison.
Error is in ON a.Name = b.Did Name column may contains alphabets,number or special characters. Did column contains only number or integers only.

Creating a calculated field table based on data in separate tables

It is straight forward to create a calculated field in a table that uses data IN the table... due to the fact that the expression builder is straight forward to use. However, it appears to me that the expression builder for the calculated field only works with data IN the table;
i.e: expression builder in table MYTABLE works with fields FIELD1.MYTABLE, FIELD2.MYTABLE etc.
Inventory Problem
My problem is that I have two 'count' fields that result from my queries that apply to INPUTQUERY and OUTPUTQUERY (gives me a count of all input data added and a count of all output data added) and now I want to subtract the two to get a stock.
I can't link the table that was created from my query because it wont be able to continually update do the relationship itself, and thus i'm stuck either using the expression builder/SQL.
First question:
Is it possible to have the expression builder reference data from other tables?
i.e expressionbuilder for:
MAINTABLE CALCULATEDFIELD.MAINTABLE = INPUTSUM.INPUTTABLE - OUTPUTSUM.OUTPUTTABLE
(which gives a difference of the two)?
Second question:
if the above isn't possible, can I do this through an SQL code ?
i.e
SELECT(data from INPUTSUM)
FROM(INPUTTABLE)
-
SELECT(data from OUTPUTSUM)
FROM(OUTPUTTABLE)
Try this:
SELECT SUM(T.INPUTSUM) - SUM(T.OUTPUTSUM) AS RESULTSUM
FROM
(
SELECT INPUTSUM, 0 AS OUTPUTSUM
FROM INPUTTABLE
UNION
SELECT 0 AS INPUTSUM, OUTPUTSUM
FROM OUTPUTTABLE
) AS T