Simple SQL statement in MS Access [duplicate] - sql

This question already has an answer here:
MS Access 2010 SQL Select Into Calculated Column Issue
(1 answer)
Closed 6 years ago.
I'm trying what should be a simple task in Access. Basically to create a new table based on a string matching query. The Hazus_Schools table already exists in my database. The Hazus_Public does not, and I'm trying to create it. The PUBLIC field is a calculated column from another field. The following snippet
SELECT * FROM Hazus_Schools INTO Hazus_Public
WHERE Type = "PUBLIC";
Gives me the following error:
Syntax error in FROM clause
Any ideas what is wrong here?

The order of your INTO and FROM is off, see W3schools Select Into
Try the following:
SELECT *
INTO Hazus_Public
FROM Hazus_Schools
WHERE Type = "PUBLIC"

Related

SQL Select AS not being recognized as column [duplicate]

This question already has answers here:
Referring to a Column Alias in a WHERE Clause
(9 answers)
Closed 1 year ago.
I am using a simple select statement and creating a column using a CONCAT function and labeling the column as Filter.
Why is the new column not being recognized?
Error message states
Invalid Column Name - Filter
You can't refer to column aliases in the where clause as the where is processed before the alias is materialised.
There are several workarounds, and assuming SQL Server you can do
select *
from table t
cross apply (values(concat(columna,columnb)))c([filter])
where [filter]='something'
Also note that the performance won't be great on large data sets since this criteria is non-sargable

Why does Access 2016 reject the syntax [duplicate]

This question already has an answer here:
MS Access: Syntax error in CREATE TABLE statement
(1 answer)
Closed 1 year ago.
I want to create a table with selected columns from an existing larger table The syntax below is what is recommended but ACCESS throws an error msg. What gives?
CREATE TABLE new_table_name AS
SELECT column1, column2
FROM existing_table_name
WHERE ....;
Every brand of SQL database can choose how complete its implementation of the SQL language is. MS Access in particular fails to support a lot of language features that are common in other brands of database.
You just have to verify the syntax you want to use is supported. You can do this by referring to the syntax documentation, for example: CREATE TABLE Statement. The syntax and description makes no mention of CREATE TABLE ... AS SELECT ...
But SELECT.INTO Statement shows that you can use the SELECT ... INTO newtable FROM ... form. The documentation says this will create newtable in the process.
MS Access doesn't have a "create table as select syntax". Instead, you can use the "select into" syntax:
SELECT column1, column2
INTO new_table_name
FROM existing_table_name
WHERE ...

Trying to duplicate a table without data [duplicate]

This question already has answers here:
Create table (structure) from existing table
(17 answers)
Closed 3 years ago.
I have a table which I would like to duplicate without any data in it (Only the columns).
So I have 2 types of databases, Oracle and Sql Server.
I have constructed this:
CREATE TABLE TMPTABLE AS SELECT * FROM USERS WHERE 1 = 0
It works fine in the Oracle database, but in the Sql Server I get this error:
Error Number:156,State:1,Class:15 Incorrect syntax near the keyword 'SELECT'.
Sql Server version: 14.0.1000.169.
try this
CREATE TABLE newtable SELECT * FROM oldtable
Without AS

Get table definition in oracle sql plus [duplicate]

This question already has answers here:
How to get Oracle create table statement in SQL*Plus
(3 answers)
Closed 7 years ago.
I'm new to sql and I have created table using create table table_name.
And now I want to get this table definition or let's say source code, I know command desc table_name but that's not what I want. Could you help me figure it out?
Check the function: DBMS_METADATA.GET_DDL
http://psoug.org/reference/dbms_metadata.html

UPDATE within a table from table name saved in the column [duplicate]

This question already has answers here:
How do I UPDATE from a SELECT in SQL Server?
(38 answers)
Closed 8 years ago.
I have a little problem, but I'm sure it s not really complicated.
It's just hard to find the key word to describe the problem and find a solution
I want to update a column in a table using parameters from this table for a query on an other table.
Example : I have Header + 2 lines
IDSOURCE, IDCIBLE, IDENTIFIANT, TABLE_CIBLE, NOM_ATTRIBUT, NOM_CHAMP_IDENTTIFIANT, NOM_CIBLE
--------------------------------------------------------------------------------------------
DMT_1000, DMT_1000, 1000, [dictionnaire].[dbo].[TABLE_CHAMPS_DATAMART], NOM_CHAMP_DMT, IDENTIFIANT_CHAMP_DATAMART, NULL
DMT_1001, DMT_1001, 1001, [dictionnaire].[dbo].[TABLE_CHAMPS_DATAMART], NOM_CHAMP_DMT, IDENTIFIANT_CHAMP_DATAMART, NULL
And I want to update the last column of each line with something like :
UPDATE
Table
SET
Table.NOM_CIBLE = SELECT table.NOM_ATTRIBUT FROM table.TABLE_CIBLE WHERE table.NOM_CHAMP_IDENTTIFIANT = table.IDCIBLE
FROM
Table
Don't know if it s clear.
Thanks for your help.
This sounds like situation where you could use a cursor. Check out this StackOverflow question How to update a column fetched by a cursor