Dash in a field name in access database table - sql

Im having problems retrieving a field from my ms-access database.
The table name is TEST and one of the field's name is HD-TEST
When i do:
SELECT * from TEST where TEST.HD-TEST='H' and i execute the query, ms-access shows me a dialog expecting the parameter HD.
Do you know what could be the reason?
Thanks a lot.
Kind Regards.
Josema.

Try to add brackets to the begin and the end of the column name (not tested, but works in SQL Server):
SELECT * from TEST where TEST.[HD-TEST]='H'

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.

Teradata Sql Assistant not showing text in the query result view

When I run a select query on an informix database using Teradata Sql Assistant all the text fields are null. But when I use another database manager like DBeaver, using a select query on the same table, I get values in the text fields. Has anyone else encountered this issue? if yes, how did you fixed it?
Thanks for the help!
I had similar issues today, try converting the text column to varchar in your select.
SELECT CAST(txt_column As VARCHAR(8000))

table with "." in its name

I was trying to use sqlFetch. The fetch works perfectly when I change the name of my table to have underlines instead of periods. So if I use the command
sqlFetch(conn, "HelloWorld_40")
It works fine. Unfortunately, my friends are all using the real name of the table
sqlFetch(conn, "HelloWorld.40")
But then it crashes and it tells me that
Error in sqlColumns(conn, "HelloWorld.40") :
'HelloWorld.40': table not found on channel
I'm guessing the period "." is illegal name for a table. But I don't want my friends to change it because it's a lot of people who would be affected. Is there a way I can call the table, or do I have to secretly go to their database, change the name while I use it and then change it back to a period (risking that I will forget, someone will read, blah blah).
Thanks.
put the table name in square brackets:
[HelloWorld.40]
It is a problem with sqlFetch which parse table name. Unfortunately it did not handle table quotes, so it's search for table 40 in schema HelloWorld. You need to directly call sqlQuery (with quoted table name, brackets for MS SQL Server):
sqlQuery(dbhandle, "SELECT * FROM [HelloWorld.40]")
Side note: you should specify which database you are using.
The best delimiter is double quotes -- that should work in most underlying databases:
"HelloWorld.40"
In MySQL, you can also use back ticks (`):
`HelloWorld.40`
In SQL Server, Access, and I think Sybase, you can also use square braces:
[HelloWorld.40]

How to Query Database Name in Oracle SQL Developer?

How do I query the database name in Oracle SQL Developer? I have tried the following and they all fail:
SELECT DB_NAME();
SELECT DATABASE();
Why do these basic MySQL queries fail in SQL Developer? Even this one fails too:
show tables;
EDIT: I can connect to the database and run queries such as:
select * from table_name_here;
EDIT 2: The database type is Oracle, this is why MySQL queries are failing. I thought it was related to the database client not the database itself. I was wrong. I'll leave the question as is for other as lost as I was.
Once I realized I was running an Oracle database, not MySQL, I found the answer
select * from v$database;
or
select ora_database_name from dual;
Try both. Credit and source goes to: http://www.perlmonks.org/?node_id=520376.
try this:
select * from global_name;
You can use the following command to know just the name of the database without the extra columns shown.
select name from v$database;
If you need any other information about the db then first know which are the columns names available using
describe v$database;
and select the columns that you want to see;
I know this is an old thread but you can also get some useful info from the V$INSTANCE view as well. the V$DATABASE displays info from the control file, the V$INSTANCE view displays state of the current instance.
Edit: Whoops, didn't check your question tags before answering.
Check that you can actually connect to DB (have the driver placed? tested the conn when creating it?).
If so, try runnung those queries with F5
To see database name,
startup;
then type
show parameter db_name;
DESCRIBE DATABASE NAME; you need to specify the name of the database and the results will include the data type of each attribute.

find and replace data in multiple records

I have a mysql 5 database table with a longtext field that permits html code (via markdown) to be entered as data. Unfortunately, I made a minor copy/paste error that I didn't catch until I had more that 200 records. Because it's the same error on each record
href:"http://someurl.com"
as opposed to
href="http://someurl.com"
it would be easier if there were some sql I could write that would allow me to find "href:" on all records and replace with "href=" in the same transaction, than if I have to edit each record individually. Is there anything I can do or am I just screwed?
You can do this:
UPDATE Data_Table
SET Html_Column = REPLACE(Html_Column, 'href:', 'href=');
if using phpmyadmin click on sql and run this UPDATETable_Name
SETColumn_Name= replace(Column_Name, 'href:', 'href=')