Anyone good with SQL?
Anyone good with SQL?
It's been a long time since I've done anything with SQL and don't feel like digging my Access book out. I'm using OpenOffice Base for a simple database I have made at work. I have entered all our clients that my departments deals with into a table. I have then created a query that will pull the clients that belong to the Hilton brand (I support phone systems for hotels.) My next step is I want to be then able to take the date from the Hilton query and add another column that says updated. The end result I'm looking for is a report of what hotels we need to perform our update on. Is there anyway I can run my Hilton Query and have it save that as a table where I can then add my new column and make a new Query to get my desired results? Or do I need to just run my Query and then manually make a new table using the data from that report? If that's the case is there anyway to get the data from Table1 to Table2 by just putting in the Primary key and it pulling the rest of the data over? I'm pretty sure there is a way to do this but like I said it's been a while. Thanks in advance and let me know if there is any more info needed.
Been looking around and this should work but it doesn't. I just get: "Syntax error in SQL expression." This is what I have.
---Create HiltonUpgrade table
Create table "HiltonUpgrade" ("HotelName" varchar(50), "City" varchar(3), "SiSID" varchar(10), "Type" varchar(50), "Load" varchar(50), "UpgradeCompleted" boolean())
---INSERT INTO HiltonUpgrade using SELECT
Insert into "HiltonUpgrade" ("HotelName", "City", "SiSID", "Type", "Load")
Select "HotelName", "City", "SiSID", "Type", "Load"
from "Customers1"
WHERE "HotelName" = 'Doubletree' OR "HotelName" = 'Embassy Suites' OR "HotelName" = 'Hampton Inn' OR "HotelName" = 'Hilton' OR "HotelName" = 'Hilton Garden Inn' OR "HotelName" = 'Home2Suites' OR "HotelName" = 'Homewood Suites'
Have you confirmed the CREATE TABLE SQL works by itself? It looks like it should work but should confirm on its own
I “think” Your INSERT INTO statement is missing the last column of the newly created table…field “upgradecompleted” which does not have a DEFAULT value the way it’s created via the CREATE TABLE SQL…perhaps try the below…syntax error looks to be the unnecessary quotation marks around table and field names…also are those the actual field names in table “Customers1”??? do they match the same field names in the new table?
Insert into HiltonUpgrade (HotelName, City, SiSID, Type, Load, upgradecompleted)
Select HotelName, City, SiSID, Type, Load, 1
from Customers1
WHERE HotelName IN ( 'Doubletree', 'Embassy Suites', 'Hampton Inn' , 'Hilton', 'Hilton Garden Inn' , 'Home2Suites' , 'Homewood Suites')
Don’t think the VALUES statement is needed before the SELECT statement because you’re using a SELECT statement to populate but that is the only other thing I can see that might be problematic.
I tried your code and it doesn't work as well. I had tried without the " " around the column names but neither way work. I have been working on another way and used some of what you showed me and currently I have:
SELECT Customers1.HotelName, Customers1.City, Customers1.State, Customers1.SiSID, Customers1.Type, Customers1.Load
INTO HiltonUpgrade
FROM Customers1
WHERE HotelName IN ( 'Doubletree', 'Embassy Suites', 'Hampton Inn' , 'Hilton', 'Hilton Garden Inn' , 'Home2Suites' , 'Homewood Suites')
It still does not work. I have even removed the Where line and still just get Synatax errors.
SQL Status: HY000
Error code: 1000
Syntax error in SQL expression
SQL Status: HY000
Error code: 1000
syntax error, unexpected $end, expecting BETWEEN or IN or SQL_TOKEN_LIKE
I'm begining to think it's just OpenOffice. Even
SELECT *
INTO HiltonUpgrade
FROM Customers1;
is giving me errors. WTF?!?!?!?!
Maybe it's SQL that is being written across mutliple lines where you may need to get into quotation marks and "line contunuation" syntax like.... ampersand, space, underscore like the example below which is only a partial statement. can you even just "SELECT * FROM Customers1" without syntax errors? If this query works in ONE code line but not in two then it's probably line continuation issues.
"INSERT INTO [Tbl ASG] ( [Date], Department, [User Int], [Customer Name], " & _
"[Branch#], [Dlr#], [Account#], [Original Contract], [Copy Contract], " & _
"[Original Title], [Copy Title], Other, Comments, Mileage, [Insurance Cancellation], " & _
"select * from Customers1" does not work. Same errors. This is my first Query and it works correctly
SELECT "HotelName", "City", "State", "SiSID", "Type", "Load" FROM "Customers1" WHERE "HotelName" IN ( 'Doubletree', 'Embassy Suites', 'Hampton Inn', 'Hilton', 'Hilton Garden Inn', 'Home2Suites', 'Homewood Suites' ) ORDER BY "HotelName", "City"
So I shouldn't need to add any additonal " " or line contunuations.
With help from a guy from another forum, I got it working. It appears I had to run the SQL command differently.
I tell you that Michael Bay ain't good with them.
this is amazing!
Grrr. I wish saw this thread earlier. SQL is 80% of what I do.
If I ever need help again, I know who to ask :)