Questions tagged [dynamic-sql]
Constructing a query at runtime with string concatenation operations and executing the query from that string.
432 questions
0 votes
1 answer
72 views
sp_executesql with ISNUMERIC(@ColumnName) not working with column name passed as parameter
Question: Why example 1 does not work while example 2 works: SQL Table to check for non-numeric values in varchar column: CREATE TABLE #t(Mycol varchar(15)) INSERT #t VALUES ('123.86'),('4a5.67'),('45....
4 votes
2 answers
333 views
Dynamic NVARCHAR(MAX) Being Truncated When 'inlining' a NVARCHAR(MAX) Parameter
The @SQL variable in the statement below is always truncated when I "inline" a variable. If I send the variable in and print it does not truncate to 4000, however, I can't bind the sent in ...
0 votes
1 answer
186 views
Why can I not capture dynamic SQL called with EXEC using the sqlserver.sql_batch_completed Extended Event?
It is my understanding that dynamic SQL is part of a batch. Yet, when I listed for sqlserver.sql_batch_completed as follows CREATE EVENT SESSION [CaptureBatch] ON SERVER ADD EVENT sqlserver....
0 votes
1 answer
113 views
T-SQL how to dynamically Pivot a tree
I've got a simple parent-child tree relationship that was built recursively Parent Child A B B E B C E NULL C NULL A F F NULL this table comes from a recursive CTE: with tree(parent, child) as (...) ...
0 votes
1 answer
113 views
How can I find all violations of a proposed foreign key on all columns with a specific name?
Let's say I have multiple tables with a column foobar. And I wish to make to make all these columns reference foobar.id as a FOREIGN KEY. The problem is I know there are violations in this schema from ...
6 votes
1 answer
1k views
How does sp_executesql interact with temporary tables?
I'm at a loss as to why some SQL leveraging sp_executesql is working the way it is when temporary tables are involved, along with INSERT and SELECT - INTO. I'm using SQL Server. Here is the code in ...
0 votes
2 answers
77 views
Does Oracle database server stored runtime dynamic SQL?
I have a plsql below that executes dynamic sql. DECLARE sql_stmt VARCHAR2(200); BEGIN sql_stmt := 'SELECT employee_name FROM employees WHERE employee_id = :1'; EXECUTE IMMEDIATE sql_stmt ...
0 votes
1 answer
1k views
Get absolute number and percentage of NULL values for each column of each table in a given schema
I'd like to extract some basic statistics about how tables are populated in a given PostgreSQL 16 schema, such as the absolute number and percentage of null values for each column in all tables in ...