Anyone good with SQL?

12 posts / 0 new
Last post
#1 Tue, 08/12/2014 - 15:00
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

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.

Tue, 08/12/2014 - 15:44
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

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'

Thu, 08/14/2014 - 09:04
Parcells2's picture
Offline
Last seen: 8 years 3 weeks ago
Joined: 01/27/2010 - 23:00
Currently Playing: 

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.

Thu, 08/14/2014 - 09:29
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

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

Thu, 08/14/2014 - 09:51
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

I'm begining to think it's just OpenOffice. Even

SELECT *
INTO HiltonUpgrade
FROM Customers1;

is giving me errors. WTF?!?!?!?!

Thu, 08/14/2014 - 10:43
Parcells2's picture
Offline
Last seen: 8 years 3 weeks ago
Joined: 01/27/2010 - 23:00
Currently Playing: 

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], " & _

Thu, 08/14/2014 - 10:50
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

"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.

Thu, 08/14/2014 - 12:22
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

With help from a guy from another forum, I got it working. It appears I had to run the SQL command differently.

Thu, 08/21/2014 - 07:48
FreeRadikal's picture
Offline
Last seen: 3 years 3 months ago
Joined: 07/22/2010 - 23:00
Currently Playing: 

I tell you that Michael Bay ain't good with them.

Thu, 08/21/2014 - 22:48 (Reply to #9)
cdn_bacon's picture
Offline
Last seen: 6 years 10 months ago
Joined: 11/18/2006 - 23:00
Currently Playing: 

FreeRadikal wrote:

I tell you that Michael Bay ain't good with them.

this is amazing!

Wed, 08/27/2014 - 21:44
VoodooHack's picture
Offline
Last seen: 6 years 3 weeks ago
Joined: 06/11/2005 - 23:00

Grrr. I wish saw this thread earlier. SQL is 80% of what I do.

Thu, 08/28/2014 - 08:48
SoulTerror's picture
Offline
Last seen: 7 years 3 months ago
Joined: 12/13/2012 - 15:28
Currently Playing: 

If I ever need help again, I know who to ask :)

Join our Universe

Connect with 2o2p