This function works: But when I try to add some text to the column name: This just fails as a syntax error on $1. Or: select * from a(‘some prefix’) doesn’t work. Is there some other syntax that does the job? Answer That’s simply not possible. SQL does not allow dynamic column names. You must assign a column alias with
Tag: dynamic-sql
How to rotate a two-column table?
This might be a novice question – I’m still learning. I’m on PostgreSQL 9.6 with the following query: My query returns the following dynamic rows: locales count en 10 fr 7 de 3 n additional locales (~300)… n-count I’m trying to rotate it so that locale values end up as columns with a single row, like this: en fr de
Like in dynamic function
The code below works well. I however have issues trying to turn it into a like statement that I need some assistance with So far, I have tried the code below but with not much success I have also tried; Answer If your stored procedure parameter is @deliverer and your dynamic SQL parameter is @pt, I believe your sp_executesql execution
How to pass table name as a parameter in update procedure in Oracle?
I am new to Oracle so please sorry the question that seems to be very easy for you. I need to get the following procedure with UPDATE query with replace function This procedure removes all spaces. But when I call it I’ve got the following error How can I modify my code to handle the problems? Thank you. Answer You
PostgreSQL dynamic query: find most recent timestamp of several unrelated tables
I have a number of tables, and many of them have a timestamp column. I can get a list of every table with a timestamp column: I can get the hightest timestamp in the sharks table as follows I would like to get a table like I’m suspecting this requires dynamic SQL, so I’m trying something like But it seems
Copy all values from source table to destination table dynamically in SQL Server. If there is some value in destination table then delete and insert
I have created 2 tables and populated the values in my source table. Now, I want to populate these values into the destination table dynamically and also check if there is any value in the destination table then delete all those values and insert them from the source. This is my approach which is not executing: Answer In your select
Conversion failed when converting the varchar value ‘ AND ID =’ to data type int
I was looking how I can parameterize table names and so I found dynamic sql queries. I finally got the proc saved, but when I execute it errors out with “Conversion failed when converting the varchar value ‘ AND ID =’ to data type int.” I have no idea what is going wrong when I try to execute this stored
Create dynamic list of tables based on list with wildcards
So I have a list of tables that I want (with wildcards) That gives me Now what I need is a list of all tables mentioned in the table config.datalist So I want a list of: id 1) all tables in database TEST of which the schemaname starts with audit id 7) all tables in database TEST in the schema
ora-00900 invalid sql statement execute immediate
I am trying to solve a task with a dynamic SQL, but facing an issue ora-00900 invalid sql statement. However, it works in the anonymous block treating the statement to be executed as a string. So where is the issue in the first case? It looks like with escape quotes, but can’t catch this. Answer As the error says, execute
Dynamic SQL stored procedure and datetime
I have a simple query that I want to convert to dynamic SQL. I have 2 input parameters: a table and a datetime. And the output is the rowcount for the table and this specific datetime. I tried different solutions. I tried the query with execute sp_executesql, I tied to add the the ”’ before and after the @P_LOAD_DATE. I