my code accepts table name parameters and my dynamic code is supposed to query a table. I consistently get the error: @sourcetbl variable must be declared. After a lot of troubleshooting, I realized …
Tag: dynamic-sql
PL/SQL Dynamic SQL : Table name not valid
I’m currently learning PL/SQL. I need to create a PL/SQL block to create a backup of all my tables like this : myTable -> myTable_old. Here’s what I got right now : DECLARE Cursor c IS SELECT …
Dynamic SQL search improvement
I have this SQL query that I am using for dynamic search in the database: In the database I have e.g.: If I provide the input Microsoft Visio I would like it to list How can I improve my SQL query to achieve this? I have done googling, but haven’t found what I want to do exactly. Answer Either pass
Displaying multiple database tables in one table
I have multiple databases with the same table (an Eventlog with different values). The names of these databases are subject to change. I am trying to display the Eventlog tables in one consolidated table with the corresponding database name. I tried to using cursor and dynamic SQL statement to achieve this with no luck. As well, I’m not sure if
Dynamic query to find all the table DML activity in all the table oracle
Hi I need to search the DML activity of specified list of tables in a schema single query since it is time consuming and hard to run individual queries ,so i am trying to prepare a dynamic sql to fetch max(ora_rowscn),SCN_TO_TIMESTAMP(max(ora_rowscn)) from all the tables so that i can use a filter and select a set of tables Query Template
STUFF function truncated result
I am trying to generate dynamic sql by querying a table and using the STUFF function and returning the results into a variable (DECLARE @dynamic_query NVARCHAR(max)). My problem is that the results returned by the STUFF function are truncated/incomplete. The content of @dynamic_query will be cut short. I can’t find any references to character limits on the STUFF function online
Dynamic SQL :: Calculate percentage of NULLs per index
I have a query that help me list all index in a database and works pretty well: Unfortunately if I uncomment the 6th line the word t.name is underlined in red and if I run the query I receive the error: How can I make this subquery work? The goal is to have a percentage of NULLs on each column
SELECT statement to remove empty columns from resultset with variable data
I’ve got a table that has been imported from a CSV as a midstep to gather data into other tables. All columns in this table may be empty but as long as one column has data, is a valid row. Because of this, there may be full rows with empty data, that are not valid to take into consideration. Here’s
Dynamically Generate SQL for Logical Sentence
Super tricky question. I have a client wanting to output true/false based on a string sentence that represents a rule. E.g. if a rule is the string: “56 AND 78”, then this means “Return …
How to Sort this MySQL Query
I am trying to insert the ORDER BY in this query to sort the Total column: With the following result: Here’s what I have tried so far but no luck: Answer I think you want: Rationale: the ORDER BY clause should go after all UNION ALL subqueries – so it needs to be outside of the GROUP_CONCAT(), in an outer