Microsoft Server studio 'script table as' for INSERT to bad syntax - sql

I have a table in a database that looks like this
I want to insert a new record. So I right click on my table, hover over 'script table as' and select the 'INSERT to' option
When I do this, I get this
My question is, what is wrong with this syntax? I seem to be getting an error before even trying to add anything. When hovering over the red lines, I get a message saying
'Incorrect syntax near <'
&
'varchar is not a recognized built in function name'
I assumed I would replace the second part with my data values. But I'm not sure.

You need to input actual values.
INSERT INTO tab_name(First_Name, Last_Name, ...)
VALUES ('John', 'Smith', ...);
Replace <col_name, datatype> placeholder with actual data.
You can also Use Templates in SQL Server Management Studio to fill template values.
Query -> Specify Values for Template Parameters
or
Highlight your query and press CTRL+SHIFT+M

Related

Access97: INSERT INTO fails without a table or a query

I need to execute a simple INSERT INTO query on an old Access97 database.
I'm starting with a very short example - which doesn't work:
INSERT INTO [MY-TABLE]( [Field1] )
VALUES ( "blabla" )
MY-TABLE is the actual name of the table and Field1 is a String field.
I get the error:
Query input must contain at least one table or query
Because I need to insert literal value, I don't want to use a query here (i.e. a SELECT FROM)
Reading also the docs (https://msdn.microsoft.com/en-us/library/bb208861(v=office.12).aspx) I don't see where my SQL is wrong.
UPDATE
Here a couple of screen shot of the actual table and fields:
here the SQL code:
Anyway...
SOLVED!!
It works even with double quotes.
The problem was the push button I was using to check: using the "View" button leads to the error above. Instead I must use the "exclamation mark".
I need to execute the query using the "exlamation mark" button instead of the view one. This is because my query has not a result set to view - hence the error I saw.
By the way I confirm the syntax is accepted both with single or double quotes.

Using SQL to extract an attachment from another table (Access 2010)?

Well basically I have two tables with a field which is the same in both table (As in the fields are both set to an attachment). Now somehow I would like to extract all the field from one table to another. When I try the following syntax the following error message occurs.
INSERT INTO Student (Photo)
SELECT Photo FROM Students_Record1;
ERROR MESSAGE : An Insert INTO query cannot contain multi-valued field.
From this error message I noticed that this got to do with the datatype as it was set to an attachment.
So I did the following code
INSERT INTO Student (Photo,Photo.FileData,Photo.FileName,Photo.FileType)
SELECT Photo,Photo.FileData,Photo.FileName,Photo.FileType FROM Students_Record1;
Which also outputs the same error as the above.
ERROR MESSAGE : An Insert INTO query cannot contain multi-valued field.
Anyone knows how can I extract an attachment from one table to another using SQL ?
Thank you!
Try to delete the first field.
Would be
INSERT INTO Student (Photo.FileData,Photo.FileName,Photo.FileType)
SELECT Photo.FileData,Photo.FileName,Photo.FileType FROM Students_Record1;

Multiple insert into in SQL Developer worksheet

I just installed SQL Developer 4 and I'm using Oracle Database 11g. I want to execute multiple insert into statements in the worksheet at once. That works fine if I copy paste via command line of SQL but in Develop 4, only one row is being inserted at a time. Is there any way to fix this? I don't want to type line by line and also don't want directly enter via data tab though the textboxes. I want be able to execute the following in one single worksheet. Please help
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00001','ivan bayross','bombay',400054,'maharashtra',15000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00002','vandana saitwal','madras',780001,'tamil nadu',0);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00003','pramada jaguste','bombay',400057,'maharashtra',5000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00004','basu navindgi','bombay',400056,'maharashtra',0);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00005','ravi sreedharan','delhi',100001,'delhi',2000);
INSERT INTO client_master(client_no,name,city,pincode,state,bal_due) VALUES ('c00006','rukmini','bombay',400057,'maharashtra',0);
From the documentation (3.2 since 4 is still beta):
SQL Worksheet toolbar (under the Worksheet tab): Contains icons for the following operations:
Execute Statement executes the statement at the mouse pointer in the
Enter SQL Statement box. The SQL statements can include bind variables
and substitution variables of type VARCHAR2 (although in most cases,
VARCHAR2 is automatically converted internally to NUMBER if
necessary); a pop-up box is displayed for entering variable values.
Run Script executes all statements in the Enter SQL Statement box
using the Script Runner. The SQL statements can include substitution
variables (but not bind variables) of type VARCHAR2 (although in most
cases, VARCHAR2 is automatically converted internally to NUMBER if
necessary); a pop-up box is displayed for entering substitution
variable values.
To run multiple statements together you need to Run Script, either from the toolbar icon or by pressing F5.
After all of the insert statements are in the "Query" Builder window, you can "hilight" (Control A) and then hit "Control" and "Enter" at the same time.

Error with simple INSERT statement

I made an insert statement that runs inside a asp.net page. It gave me an error, so I went to the sql server and ran the statement as it should be and used it to compare with what I wrote in the asp.net page. The thing is, it it writen properly but it doesn't work. It can't seem to detect the database or the tables at all and tells me the table doesn't exist and neither do the colums. The statement looks like this:
INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ("Planta 1", "Planta")
I have also tried using [dbo].[Places] and simply Places but it gives me an error at the place of the table saying it is an Invalid object name. What is it doing?
Don't use double quotes for string delimiters; use single quotes.
INSERT [Remisiones].[dbo].[Places] (Name, Type) VALUES ('Planta 1', 'Planta');

Is there a web site where I can paste a SQL Insert statement and have it break it out by column?

I've been working on an application that has no discernable data access layer, so all the SQL statements are just built up as strings and executed. I'm constantly confronted by very long INSERT statements where I'm trying to figure out what value in the VALUES list matches up with what column in the column name list.
I was about to create a little helper application where I could paste in an INSERT statement and have it show me a list of values matched up with the column names, just for debugging, and I thought, "someone else has probably done this already."
Does anyone know of a web site where I can just paste in an INSERT statement and have it show me a two column table with column names in the first column and values in the second column?
not a website but have you tried either visual studio or Sql Server Management studio. Both of these are able to do this.
You can use SQL Server Management studio or Visual Studio (with Server Explorer) to do that. For SSMS, follow these steps:
On a random table, click "Edit Top 200 Rows"
Open the SQL pane and paste your Insert script.
Open the Criteria Pane, which displays the insert column value pairs.
http://www.dpriver.com/pp/sqlformat.htm
I use Red Gate SQL Prompt for all my re-formatting.
Even though it is unnecessary (and unused), I often use aliases to make it easier to line things up, so instead of:
INSERT INTO tbl
SELECT 2 * y
FROM other_tbl
I usually do:
INSERT INTO tbl (x)
SELECT 2 * y AS x
FROM other_tbl