insert query in Open office Base

Asked by gautam tarade

Hi,
   Where will I get an option for insert record query in Open Office base 3.1.0
I have got the Select query but couldnt find insert query.
Pl help.
Gautam

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu openoffice.org Edit question
Assignee:
No assignee Edit question
Solved by:
Tony Pursell
Solved:
Last query:
Last reply:
Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#1

Please read this http://www.linuxjournal.com/content/creating-queries-openofficeorg-base it might helps.

Hope this helps

Revision history for this message
gautam tarade (gautam-tarade) said :
#2

Hi,
   I had tried to modify an already existing select query which is -
SELECT "DATAA"."name " AS "name ", "DATAA"."password" AS "password" FROM "DATAA" "DATAA" .Its running successfully. Now I want to modify select query to delete query which is
DELETE FROM "DATAA" WHERE "NAME"="GAUTAM". But its giving error that
" -The given command is not a SELECT statement.Only queries are allowed.
DELTE FROM "DATAA" WHERE "NAME"="GAUTAM" -".
And another thing is that I am using Windows XP.
Pl suggest me.
Thanks and regards,
Gautam

Revision history for this message
Tony Pursell (ajpursell) said :
#3

Hi Gautam

The general format for a simple SQL insert query is

INSERT INTO "table" ("col1_name","col2_name",...) VALUES (value_for_col1,value_for_col2,...)

The values must be given in a valid way for HSQLDB. For a VARCHAR that would be a string in quotes. I'm not sure about other data types. You might have to experiment. HSQLDB likes all its table and column names in quote - I think you know that already.

Instead of a VALUES statement, you can have a SELECT statement, in which case, everything selected is inserted in to the table.

Tony

Revision history for this message
gautam tarade (gautam-tarade) said :
#4

Hi Tony,
    I had tried -
INSERT INTO "DATA"("NAME","PASSWORD") VALUES ("ABC","PQR"); AND
INSERT INTO "DATA"("NAME","PASSWORD") VALUES (ABC,PQR); .....BUT both are not working.Error comes like ...."The given command is not a SELECT statement.Only queries are allowed."
Both columns has Data Type Varchar. If possible pl provide me ur mail id ,i shall send u snap shots.
Pl help.

Gautam

Revision history for this message
Tony Pursell (ajpursell) said :
#5

Hi Gautam

You need to enter this type of SQL using Tools > SQL. I guess you are entering it as a stored 'Query', which has to be a SELECT.

If you need to find my email address, click on my name above, then on 'Overview'.

Tony

Revision history for this message
gautam tarade (gautam-tarade) said :
#6

Hi Tony,
   I had tried to execute through Tools > SQL. But unfortunately its giving same error.Oh god! pl help me....You'll get snaps on ur mail.Have a look.

Gautam Tarade

Revision history for this message
Tony Pursell (ajpursell) said :
#7

Hi Gautam

This is what you need:

INSERT INTO "DATAA" ("id","name","password") VALUES (1,"ABC","PQR")

Note:

1. Data names are case sensitive
2. You must specify a value for the primary key column

Tony

PS If this answers your question, please mark it as Solved.

Revision history for this message
gautam tarade (gautam-tarade) said :
#8

Hi Tony,
  I tried above said query but still giving an error like "column not found".
Check snap attached in mail.

Gautam

Revision history for this message
Tony Pursell (ajpursell) said :
#9

Hi Gautam

I can't see what is wrong. Is it possible for you to email the whole database to me? Or if there is confidential data in it, make a new data base, with a copy of the DATAA table in it, that still gives this error.

By the way, there are other ways of putting new data into a table. For instance, by making a form to do it, or by typing data into a spreadsheet and copying the data in with Paste > Append.

Tony

Revision history for this message
gautam tarade (gautam-tarade) said :
#10

Hi Tony,
  I had email u database and HTMl file along some descriptions.

Gautam

Revision history for this message
Best Tony Pursell (ajpursell) said :
#11

Hi Gautam

This SQL works in the database you sent me:

INSERT INTO "DATAA" ("id ","name ","password") VALUES (11,'ABC','PQR')

Note:
1. Two column names have spaces after them.
2. Double quotes are for data names (table, columns, etc). String values need single quotes.

When you are embedding SQL into programs and scripts, double quotes (") often have a special meaning to the programming/script language. The SQL is usually a string, so it has to be double quoted for the language to recognise it as such. The quotes in the original SQL have to be doubled, so they don't look like the language's end of string quote, eg

"INSERT INTO ""DATAA"" (""id "",""name "",""password"") VALUES (11,'ABC','PQR')"

I will try and have a look at your macros, but that is not my area of expertise.

OpenOffice.org has its own forums at

http://user.services.openoffice.org/en/forum/

where you will find lots of help.

Tony

Revision history for this message
gautam tarade (gautam-tarade) said :
#12

Hi Tony,
    Thanks for your reply.The insert query ran successfully but through Tools> SQL.Thanks for your valuable time.

Regards,
Gautam

Revision history for this message
gautam tarade (gautam-tarade) said :
#13

Thanks Tony Pursell, that solved my question.