Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to implement this code into my script but I get a syntax error
INSERT INTO prospectstbl ( 'customerNumber', 'namePerson1', 'LnamePerson1', 'street', 'city', 'state', 'zip', 'homePhone', 'cellPhone', 'clientSince', 'clientLevel', 'closingDate', 'lastPaymentDate', 'currentBalance', 'repurchaseDate', 'repurchaseAmount', 'delinquentBalance', ) VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
and the error I get:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''customerNumber', 'namePerson1', 'LnamePerson1', 'street', ' at line 2
Any help would be greatly appreciated.
remove the '' at the column names and the , at the last column:
INSERT INTO prospectstbl ( customerNumber, namePerson1, LnamePerson1, street, city,
state, zip, homePhone, cellPhone, clientSince, clientLevel, closingDate,
lastPaymentDate, currentBalance, repurchaseDate, repurchaseAmount, delinquentBalance )
VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
There is a comma , after 'delinquentBalance'
use
`
instead of
'
And remove , after , delinquentBalance
or you can remove list of your columns
INSERT INTO prospectstbl VALUES ('20713254', 'Sonia', 'Amaya', '338 Railroad Ave', 'Ctr Moriches', 'NY', '11934', '6318788386', '6318137972', '10/24/2002', '1', '7/26/2011', '8/11/2011', '$792.15', '', '$0.00', '$0.00')
IIRC, single quotes (') are generally used for quoting literal values (strings and such) and indicating that certain tokens are NOT fieldnames. Graves (`) are used to indicate fields.
Try quoting your column names with graves (`) instead.
Also, as others have said, you have an extra comma at the end of your column name list. Remove this as well.
Related
I am a relative beginner in SQL (Learned and forgotten many times) and entirely self taught so please excuse my likely lack of proper terminology. I made a query that pulls items that have been returned, each items' row has a return code. Here is a result sample:
In the final report(Created with Visual Studio), I would like to be able to have a count of returns by return type but I would need to consolidate the 40 or so return codes into 4 or 5 return type groups. So RET_CODE values ) and . are both product quality issues and would count in the "Product Quality" row.
I could use some help with what the best way to accomplish this would be.
Thank You
Andrew
The bad way!
You could do this by creating the grouping within your SQL statement with something like
SELECT
*,
CASE
WHEN RET_CODE IN ('.', ')') THEN 'Quality Error'
WHEN RET_CODE IN ('X', 'Y', 'Z') THEN 'Some Other error'
ELSE [Desc1]
END AS GroupDescription
FROM myTable
The problem with this approach is that you have to keep repeating it every time you want to something similar.
The better option. (but not perfect!)
Assuming you do not already have such a table...
Create a table that contains the grouping. You can use this in the future whenever you need to do this kind of thing.
For example.
CREATE TABLE dbo.MyErrorGroupTable (RET_CODE varchar(10), GroupDescription varchar(50))
INSERT INTO dbo.MyErrorGroupTable VALUES
('.', 'Quality Error'),
(')', 'Quality Error'),
('X', 'Some Other Error'),
('Y', 'Some Other Error'),
('.', 'Some Other Error'),
('P', 'UPS Error'),
('A', 'PAck/Pick Error')
etc....
Then you can simply join to this table and use the GroupDescription in your report
e.g.
SELECT
a.*, b.GroupDescription
FROM myTable a
JOIN MyErrorGroupTable b ON a.RET_CODE = b.RET_CODE
Hope this helps...
You're looking for the GROUP BY clause.
Currently using PHPMyAdmin, and I am trying to insert some data into a SQL Table.
The error that I am getting is Unexpected Beginning of Statement (near 'brand')
Brand is on the second line of the SQL statement.
The data that I am trying to enter:
INSERT INTO 'vehicles'
('reg_no', 'category', 'brand', 'description', 'dailyrate') VALUES
('BA5923W', 'car', 'Toyota', 'black 4 door 2.6 engine ', '9.99'),
('BA6611A', 'car', 'NISSAN ', '4 Door Saloon, Automatic', '9.99'),
('BM1245a', 'car', 'Golf', NULL, '9.00'),
('GA5955E', 'truck', 'NISSAN CABSTAR 3.0', 'Lorry, Manual ', '18.99')
cheers
You have an syntax error at you query.
For columns names you should use Grave Accent ` char like
(`reg_no`, `category`, `brand`, `description`, `dailyrate`)
and for data line Apostrophe ' char like
('BA5923W', 'car', 'Toyota', 'black 4 door 2.6 engine ', '9.99')
Fixed. I was not closing the block of SQL code that created the table, which comes before this.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to update my whole sql table except some rows. Is it possible?
I am trying with this query but not work.
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id`
!IN ('5','6','7')
It seems like you meant to use the not in operator:
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id` NOT IN ('5', '6', '7')
-- Here ------------^
Use NOT IN instead of !IN
UPDATE `boon_rise`.`users`
SET `zip` = '0'
WHERE `users`.`id`
NOT IN('5','6','7')
Yes it is possible :
Update 'boon_rize'.'users'
Set 'zip'='0'
Where 'users'.'id'
Not In ('5','6','7')
Good Luck.
INSERT INTO Employees (fname, lname, address, city, state, zip, phone)
VALUES ('Gustavo', 'Fring’, "125 Birdy Lane", ‘Tucson’, ‘AZ’, #85705#, #520-535-5323#);
Error code: "Syntax error in query expression "Fring’, "125 Birdy Lane", ‘Tucson’, ‘AZ’, #85705#, #520-535-5323#);.
For the life of me I can not figure this out.
Are the hash symbols # supposed to be part of the inserted strings?
Also you need to use normal single quotes '' for all strings, not typographic ones ‘’.
VALUES ('Gustavo', 'Fring', '125 Birdy Lane', 'Tucson', 'AZ', '85705', '520-535-5323')
I'm not sure why you are putting " around the address and # around the numbers. Doesn't ' work?
I am attempting to use the following insert command in SQL Sever Management Studio 2012:
INSERT INTO 'F' ('date', 'open', 'high', 'low', 'close', 'volume', 'amount_change','percent_change')
VALUES ('2012-12-19', 11.79, 11.85, 11.62, 11.73, 54884700, -0.06, -0.508906)
When I attempt this the error I get is
parameters supplied for object F which is not a function
I can confirm that there is a table F. I have tried various syntax using dbo.f, "F", 'F', [dbo].[F], all to no avail.
You need to remove the single quotes from the table name and the column names. If you want them escaped use brackets [].
INSERT INTO [F] ([date], [open], [high], [low], [close], [volume],
[amount_change], [percent_change])
VALUES ('2012-12-19', 11.79, 11.85, 11.62, 11.73, 54884700, -0.06, -0.508906)
Just a tidbit for your information, there is session setting that allows double quotes (ISO rules) for table and column names.
-- Set option on
SET QUOTED_IDENTIFIER ON
GO
-- Insert data
INSERT INTO "F" ("date", "open", "high", "low", "close", "volume", "amount_change","percent_change")
VALUES ('2012-12-19', 11.79, 11.85, 11.62, 11.73, 54884700, -0.06, -0.508906)
Check out this technet article for more details.
http://technet.microsoft.com/en-us/library/ms174393.aspx
TSQL is a big product with many little idiosyncrasies.
Sincerely
John
www.craftydba.com
You can use [F] for the table and make sure you are in the same database. It appears to work fine when I test it.
INSERT INTO [F] ('date', 'open', 'high', 'low', 'close', 'volume', 'amount_change','percent_change')
VALUES ('2012-12-19', 11.79, 11.85, 11.62, 11.73, 54884700, -0.06, -0.508906)