SELECT all from v_catalog.columns not showing ALL columns - sql

I'm running the following statement because I'm looking for a particular column:
SELECT * FROM v_catalog.columns
The result of this query only shows me columns for five schemas.
On the other hand, the dropdown in Toad's Object Explorer will display over 30 table schemas. I would think that all these tables would be displayed in the query above. I have read access to one of the tables that's not being displayed in the select above, so it's not permission issues.
Am I missing something?

I ended up using VIEW_COLUMNS. Also, the column names would all need to be upper case. It worked.

Related

Column Hardware_ID get's automatically renamed to Hardware-ID

can someone explain why this happens?
I don't like to call the column [Hardware-ID] if I can help it because I have to add brackets in my code if I use the dash... but it seems if I name id anything else (I tried dbhardwareid as well as Hardware_ID), I leave the table in a seemingly inconsistent status where the select shows a name different than the design view.
I deleted and recreated the table a number of times to no avail.
My guess is that table exists under two different schemas, perhaps you are looking under one schema in Object Explorer and different schema in Query Window. Could you verify the schema?

oracle Report Builder - Using Case in a query produces symbol?

I am using Oracle Report builder and I've noticed when I use the case function
Case Column
when this then that
when this then that
else this
end
in a query it produces this symbol-
Symbol
. This causes issues with the final output where duplicates occur.
Any feedback would be appreciated.
You're talking about an icon which looks like a "C/D", next to query name, right? If so, it represents a non-linkable query.
Documentation (2.3.5 About non-linkable queries) says:
A non-linkable query is a detail query that contains column objects
that prevent the query from being linked to via a column-to-column
link (when you create a column-to-column link, Reports Builder adds a
WHERE clause to your query). If you attempt to create such a link, a
message dialog box displays, which prompts you to choose whether to
create a group-to-group query (using the parent groups), or to cancel
the operation. A non-linkable query displays a non-linkable icon in
its title bar (C/D).
Instead, you can create a group-to-group link (when you create a
group-to-group link, Reports Builder does not add a WHERE clause to
your query) between the two queries and add a WHERE clause to the
child query’s SELECT statement, using a bind variable to reference the
parent column.
For example, suppose you want to create a column-to-column link
between the ADDRESS.STREET column in your child query and the LOC1
column in your parent query. You can create a group-to-group link, and
then modify the child query SQL statement to say: SELECT * FROM EMP E
WHERE E.ADDRESS.STREET = :LOC1
I'm not sure it is related to your problems with "duplicates". The simplest way to get rid of them is to use DISTINCT keyword, e.g. select distinct this, that from ... but the actual solution might differ, depending on what you really have & do.

Access Query based on ComboBox returning more values than selected in combo box

The following SQL is a simple query but I can't figure out why it is returning more results than it should. The combobox 5 on Form1 has a drop down selection of 1,2,3,4, or 5. If I leave this blank, it will return the entire data set, how if I select 2 as an example, the data set returns data where Field1 is 2 as well as others such as 1,3,4, or 5.
Any thoughts? I am connected to Table1 through an ODBC connection
SELECT Table1.*
FROM Table1
WHERE (((Table1.Field1)=Forms!Form1!CMB5 Or IsNull(Forms!Form1!CMB5)));
Apparently details are important(jk they always are). when creating an ODBC connection, it asks a very important question which is to select a unique identifier. I did not select a unique identifier which was causing the errors with my views. I found the answer here "Why does linked view give different results from MS Access vs SQL Manager?".

BigQuery - remove unused column from schema

I accidentally added a wrong column to my BigQuery table schema.
Instead of reloading the complete table (million of rows), I would like to know if the following is possible:
remove bad rows (rows with values contains the wrong column) by running a "select *" query on the table with some kind of filter, and saving result to same table.
removing the (now) unused column.
Is this functionality (or similar) supported?
Possibly the "save result to table" functionality can have a "compact schema" option.
The smallest time-saving way to remove a column from Big Query according to the documentation.
ALTER TABLE [table_name] DROP COLUMN IF EXISTS [column_name]
If your table does not consist of record/repeated type fields - your simple option is:
Select valid columns while filtering out bad records into new temp table
SELECT < list of original columns >
FROM YourTable
WHERE < filter to remove bad entries here >
Write above to temp table - YourTable_Temp
Make a backup copy of "broken" table - YourTable_Backup
Delete YourTable
Copy YourTable_Temp to YourTable
Check if all looks as expected and if so - get rid of temp and backup tables
Please note: the cost of above #1 is exactly the same as action in first bullet in your question. The rest of actions (copy) are free
In case if you have repeated/record fields - you still can execute above plan, but in #1 you will need to use some BigQuery User-Defined Functions to have proper schema in output
You can see below for examples - of course this will require some extra dev - but if you are in critical situation - this should work for you
Create a table with Record type column
create a table with a column type RECORD
I hope, at some point Google BigQuery Team will add better support for cases like yours when you need to manipulate and output repeated/record data, but for now this is a best workaround I found - at least for myself
Below is the code to do it. Lets say c is the column that you wants to delete.
CREATE OR REPLACE TABLE transactions.test_table AS
SELECT * EXCEPT (c) FROM transactions.test_table;
Or second method and my favorite is by following below steps.
Write Select query with the columns you want to exclude.
Go to Query Settings
Query Settings
In Destination setting Set destination table for query results, enter project name, Dataset name and table name exactly same as you entered in Step 1.
In Destination table write preference select Overwrite table.
Destination table settings
Save the Query Setting and run the query.
Save results to table is your way to go. Try on the big table with the selected columns you are interested, and you can apply a limit to make it small.

Actual column names instead of * in T-SQL

I have the following query (sample)
SELECT *
FROM Table_1 1 INNER JOIN
Table_2 2 ON 1.C1 = 2.C1 INNER JOIN
Table_3 3 ON 2.C2 = 3.C2 INNER JOIN
Table_4 4 ON 3.C3 = 4.C3
The output is of 10+ columns.
When I hover over * (after "SELECT") I get a tooltip with all different column names from those 4 tables.
Is there a way to easily switch from * to those column names instead of typing each one of them after SELECT?
Thank you
I'm assuming you're working in Management Studio. If so, go to the Object Explorer and open up your Table. Left click on the Columns folder and drag it to your query window. All the columns for that table will be listed.
From the Object Explorer of SQL Server Management Studio, you can expand a table (so you see the Columns, Keys, Indexes, etc folder breakdown). Dragging the Columns folder to your query window will give you a comma separated list of the column names.
Please note: If there are duplicate column names among your four tables, you will have to properly quantify these columns properly.
I see your query references 4 tables.
To avoid having to locate and expand the 4 different objects in object explorer you can also select the query text in management studio, right click and choose "Design Query in Editor" then copy the column names out of the expanded list
Copying the column names rather than simply pressing OK avoids the designer messing up your formatting and possibly your query as well.
Expanding wildcards is part of the functionality of Redgate SQL Prompt if you have this need frequently.
If you use DataGrip for writing SQL, you can press Alt+Enter -> Expand column list