MS Access database: Select statement error - sql

I am trying following query in MS Access 2010 database:
Query:
SELECT ID, Title, Priority, Workflow_Instance_Step_ID:ID
FROM Task
Error:
Error Source: Microsoft Office Access Database Engine
Error Message: Syntax error (missing operator) in query expression 'Workflow_Instance_Step_ID:ID'
I know that field "Workflow_Instance_Step_ID:ID" is giving error as it has ':' operator, but I cant change it as it it coming from share point list.
I have tried '[Workflow_Instance_Step_ID:ID]' but still its giving an error.
Please give me your suggestion on the same.

I am unable to recreate your issue, at least with a native Access table in Access 2010. I created a table named [baz] with a single text field named [foo:bar]
foo:bar
-------
this
is
a
test
and the query
SELECT [foo:bar] FROM baz;
works fine, so a field name containing a colon character does not seem to cause problems for Access SQL as such.
An ODBC linked table to a SQL Server table with the same structure does not cause problems either.
In both cases the queries were run from within Access 2010 itself.

So we might be in diagnosis mode, so lets try
SELECT * FROM Task
and then look at the FieldNames that come back.

Related

Identical SQL query works on some tables but errors out on other tables same in the same DB

I'm a finance person (little programming background) so I maybe asking something obvious for database programming experts but will appreciate any advice
Background:
I'm accessing Oracle NetSuite database via ODBC from Microsoft SQL Management Studio
Connection as a Linked Server is established successfully
I'm trying to execute the following SQL statements:
select * from [NETSUITE_SB2].[SB-B].[Administrator].[VARIANCE] -- success
select * from [NETSUITE_SB2].[SB-B].[Administrator].[WTAX_JOB] -- "Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "MSDASQL" for linked server "NETSUITE_SB2" does not contain the table ""SB-B"."Administrator"."WTAX_JOB"". The table either does not exist or the current user does not have permissions on that table."
Upon some testing, it appears that whether the query is successfully run depends on whether the table name contains "_" (underscore) - for all tables without underscore I've tried, it worked, for all tables with underscore that I've tried, it failed.
Can anyone help me figure out how to overcome this?
Thanks in advance!
Instead of using a 4-part name in SQL Server and having SQL Server generate a query for the linked server, try using the OPENQUERY function and passing a query in the target system's SQL dialect directly. Something like:
select *
from OPENQUERY([NETSUITE_SB2], 'select * from [SB-B].[Administrator].[WTAX_JOB]' )
I just encountered this myself in a new instance that I just set up. I had been using Suite Connect for 4+ years without running into this issue before.
I believe the issue with the situation here is the "[SB-B]" part of the name because it contains the "-" dash. I found that a "," comma or "." period were the issue with my name [Acme, Inc.]. Ether the period or comma threw the error.
The second part of the 4-part name is the NetSuite [Company Name] under General Settings Company Info. I changed the name in NetSuite and removed the comma and period and the problem went away. Maybe most special characters cause the issue?
Just remember you'll have to update your second part name in each query you created before.
While using OPENQUERY is a solution, I just don't like the extra quotes needed so I prefer normal SQL.

visual studio 2012 query builder

Can anybody tell me what does the error mean? Whenever I open the query builder it will prompt with an error indicating that SQL syntax errors were encountered.
https://msdn.microsoft.com/en-us/library/ms189012.aspx
I looked at the following page in MSDN but I don't understand what it means...
For instance, what do these bullet points from the MSDN article mean?
The SQL statement is incomplete or contains one or more syntax errors.
The SQL statement is valid but is not supported in the graphical panes (for example, a Union query).
The SQL statement is valid but contains syntax specific to the data connection you are using.
USER (which you've apparently decided is an appropriate table name) is a SQL Server reserved word.
The best solution is to rename your table, so you don't have to escape the table name every time you want to query it and to make it clear it's your user data (hey, there's a table name suggestion - userdata).
The other option is to escape the name by surrounding it with square brackets:
SELECT * FROM [users]
Note that it will get old fast having to do this with every query. Again, the best solution would be to rename the table to something that isn't a reserved word.

SQL and IBMDASQL

I'm trying to query a set of files.
Out of the 15 I have to query 3 of them are returning the error:
Msg 7314, Level 16, State 1, Line 1
The OLE DB provider "IBMDASQL" for linked server "Server name here" does not contain the table "system.lib.file". The table either does not exist or the current user does not have permissions on that table.
I am using SQL and made a linked server using the IBMDASQL driver.
Like I said, 3 files out of the 15 are only giving me this problem.
When I do a wrkobj on the files I see that public has all permission, and I've added the specific user account just in case.
When I connect using a basic ODBC and microsoft query I don't even see the file on the list. When I log directly into the iSeries I can see and manipulate the files. .
Now using the alternate file name. But getting an insert error. As asked, here is the code and then below the exact error.
INSERT INTO [PARKWAY-TRAIN].S60017.ORDERF912.NC_NURS_ORD_REF
(RECORD_ID, NURSING_ORDER_CD, ORDER_DESCRIPTION, LONG_DESCRIPTION, ORDER_TYPE, FREQUENCY_CD, FREQ_PM_MAINT, NOTE_REQUIRED_STS, NOTE_TEMPLATE, TPL_STATUS, FORM_ID, PARAMETER_ID, COSIG_REQ)
SELECT STND.RECORD_ID, STND.NURSING_ORDER_CD, STND.ORDER_DESCRIPTION, STND.LONG_DESCRIPTION, STND.ORDER_TYPE, STND.FREQUENCY_CD, STND.FREQ_PM_MAINT, STND.NOTE_REQUIRED_STS, STND.NOTE_TEMPLATE, STND.TPL_STATUS, STND.FORM_ID, STND.PARAMETER_ID, STND.COSIG_REQ
FROM [MODEL2].TNICLN2.ORDERF143.NC_NURS_ORD_REF STND
WHERE STND.RECORD_ID <> 'D' AND NOT EXISTS (SELECT HOSP.NURSING_ORDER_CD FROM [PARKWAY-TRAIN].S60017.ORDERF912.NC_NURS_ORD_REF HOSP WHERE HOSP.NURSING_ORDER_CD = STND.NURSING_ORDER_CD)
The error message:
OLE DB provider "IBMDASQL" for linked server "PARKWAY-TRAIN" returned message "SQL0104: Token . was not valid. Valid tokens: .
Cause . . . . . : A syntax error was detected at token .. Token . is not a valid token. A partial list of valid tokens is . This list assumes that the statement is correct up to the token. The error may be earlier in the statement, but the syntax of the statement appears to be valid up to this point. Recovery . . . : Do one or more of the following and try the request again: -- Verify the SQL statement in the area of the token .. Correct the statement. The error could be a missing comma or quotation mark, it could be a misspelled word, or it could be related to the order of clauses. -- If the error token is , correct the SQL statement because it does not end with a valid clause.".
Msg 7343, Level 16, State 2, Line 1
The OLE DB provider "IBMDASQL" for linked server "PARKWAY-TRAIN" could not INSERT INTO table "[PARKWAY-TRAIN].[S60017].[ORDERF912].[NC_NURS_ORD_REF]".
If I run just the Select portion of the code, I get a return 503 lines to be exact. It only fails when I throw in the insert portion of the code.
IBM says to correct the token. I've got no clue as to which token is in error to correct though.
The 'Table not found' error is very suspicious. Using STRSQL:
select table_name, table_schema,
base_table_name, base_table_schema, base_table_member,
system_table_name, system_table_schema
from systables
where table_name = 'NC_NURS_ORD_REF'
Check to see that the table named NC_NURS_ORD_REF in library ORDERF912 is really associated with the system table name NCORDER in the library ORDERF912.
The syntax error is equally suspicious. Given that this is a cross-system query, I doubt you'll be able to run it as-is from the IBM i STRSQL command. That would mean that the proper multi-system database configuration is set up on the i side.
I found someone with a similar problem and it looks like it's on the Microsoft side: http://bytes.com/topic/db2/answers/447753-error-inserting-into-iseries-db2-table-long-name-via-sql-server-2000-linked-server I think his workaround was to use the OPENQUERY() form.
One thing you can definitely check on the IBM i side is whether journaling is turned on for ORDERF912.NC_NURS_ORD_REF. This is important because you need to use the right commit level. Take the results of the previous query against SYSTABLES and use the SYSTEM_TABLE_NAME to do a DSPFD. Look for the text 'File is currently journaled'. If the table is not journaled, you have several choices. The best choice is to start journaling the file, but if that's not available, try INSERT... WITH NC. Or turn off commitment control at the driver.
Also, have a look at the following IBM technote to make sure the linked server is set up properly: http://www-01.ibm.com/support/docview.wss?uid=nas8N1014514

Unable To Run Access Report With Column Name Which Has Special Character

I'm trying to run a report in Access that references a poorly named column: Vendor#. For those of you not familiar with Access: '#' is a reserved keyword with special meaning. I've been trying to run the report and every time I do a popup appears asking for a value for the column: in other words it keeps seeing it as a variable name. I've tried a number of variations on the name including: [Vendor#], 'Vendor#', ['Vendor#']. I tried an Alias but then I encountered the same issue in the where clause referencing the Alias. No I can't change the schema to rename the column to something more appropriate. Any help is appreciated.
Here is the query:
SELECT * FROM dbo_Vendors
WHERE ((dbo_Vendors.[Vendor#]) = [Forms]![frm_Report_Vendor]![VendorNumber])
I have just tested with a linked sql server table having a column called Vendor#. I can create a report and it runs correctly.
Can you save the query and test that the query runs? I suspect that you may have a misspelled form reference, because I have tested the whole scenario and it works for me. I do not think the report has anything to do with it.

SQL Server reports 'Invalid column name', but the column is present and the query works through management studio

I've hit a bit of an impasse. I have a query that is generated by some C# code. The query works fine in Microsoft SQL Server Management Studio when run against the same database.
However when my code tries to run the same query I get the same error about an invalid column and an exception is thrown. All queries that reference this column are failing.
The column in question was recently added to the database. It is a date column called Incident_Begin_Time_ts .
An example that fails is:
select * from PerfDiag
where Incident_Begin_Time_ts > '2010-01-01 00:00:00';
Other queries like Select MAX(Incident_Being_Time_ts); also fail when run in code because it thinks the column is missing.
Any ideas?
Just press Ctrl + Shift + R and see...
In SQL Server Management Studio, Ctrl+Shift+R refreshes the local cache.
I suspect that you have two tables with the same name. One is owned by the schema 'dbo' (dbo.PerfDiag), and the other is owned by the default schema of the account used to connect to SQL Server (something like userid.PerfDiag).
When you have an unqualified reference to a schema object (such as a table) — one not qualified by schema name — the object reference must be resolved. Name resolution occurs by searching in the following sequence for an object of the appropriate type (table) with the specified name. The name resolves to the first match:
Under the default schema of the user.
Under the schema 'dbo'.
The unqualified reference is bound to the first match in the above sequence.
As a general recommended practice, one should always qualify references to schema objects, for performance reasons:
An unqualified reference may invalidate a cached execution plan for the stored procedure or query, since the schema to which the reference was bound may change depending on the credentials executing the stored procedure or query. This results in recompilation of the query/stored procedure, a performance hit. Recompilations cause compile locks to be taken out, blocking others from accessing the needed resource(s).
Name resolution slows down query execution as two probes must be made to resolve to the likely version of the object (that owned by 'dbo'). This is the usual case. The only time a single probe will resolve the name is if the current user owns an object of the specified name and type.
[Edited to further note]
The other possibilities are (in no particular order):
You aren't connected to the database you think you are.
You aren't connected to the SQL Server instance you think you are.
Double check your connect strings and ensure that they explicitly specify the SQL Server instance name and the database name.
In my case I restart Microsoft SQL Sever Management Studio and this works well for me.
If you are running this inside a transaction and a SQL statement before this drops/alters the table you can also get this message.
I eventually shut-down and restarted Microsoft SQL Server Management Studio; and that fixed it for me. But at other times, just starting a new query window was enough.
If you are using variables with the same name as your column, it could be that you forgot the '#' variable marker. In an INSERT statement it will be detected as a column.
Just had the exact same problem. I renamed some aliased columns in a temporary table which is further used by another part of the same code. For some reason, this was not captured by SQL Server Management Studio and it complained about invalid column names.
What I simply did is create a new query, copy paste the SQL code from the old query to this new query and run it again. This seemed to refresh the environment correctly.
In my case I was trying to get the value from wrong ResultSet when querying multiple SQL statements.
In my case it seems the problem was a weird caching problem. The solutions above didn't work.
If your code was working fine and you added a column to one of your tables and it gives the 'invalid column name' error, and the solutions above doesn't work, try this: First run only the section of code for creating that modified table and then run the whole code.
Including this answer because this was the top result for "invalid column name sql" on google and I didn't see this answer here. In my case, I was getting Invalid Column Name, Id1 because I had used the wrong id in my .HasForeignKey statement in my Entity Framework C# code. Once I changed it to match the .HasOne() object's id, the error was gone.
I've gotten this error when running a scalar function using a table value, but the Select statement in my scalar function RETURN clause was missing the "FROM table" portion. :facepalms:
Also happens when you forget to change the ConnectionString and ask a table that has no idea about the changes you're making locally.
I had this problem with a View, but the exact same SQL code worked perfectly as a query. In fact SSMS actually threw up a couple of other problems with the View, that it did not have with the query. I tried refreshing, closing the connection to the server and going back in, and renaming columns - nothing worked. Instead I created the query as a stored procedure, and connected Excel to that rather than the View, and this solved the problem.