CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 19:12:43 GMT
content-type: text/html; charset=utf-8
cf-ray: 963d7dabce65a9b7-BLR
cf-cache-status: DYNAMIC
cache-control: private
set-cookie: prov=2d04759d-a075-48b2-831c-2f30a5e795fc; expires=Thu, 23 Jul 2026 19:12:43 GMT; domain=.stackexchange.com; path=/; secure; httponly
strict-transport-security: max-age=31536000; includeSubDomains
vary: Accept-Encoding
content-security-policy: upgrade-insecure-requests; frame-ancestors 'self' https://stackexchange.com
x-clacks-overhead: GNU Terry Pratchett
x-frame-options: SAMEORIGIN
x-request-guid: 2a8e7838-9ac1-4ad4-ba1b-7806155640c7
x-worker-origin-response-time: 598000000
x-dns-prefetch-control: off
set-cookie: prov=2d04759d-a075-48b2-831c-2f30a5e795fc; Path=/; HttpOnly; Domain=stackexchange.com
set-cookie: __cf_bm=OzBeFepfUnNR9nC5lhJcy6.zWvbkVSgr2eWbBElUhxc-1753297963-1.0.1.1-rJvmvE1HE76vu687W0NV6GSf2lnETuHCMI8nJKOEbsXKJtuLqMPn2MmpBbM3oYsa1nw.Bh.Aj4ObB5hpyYaaUV5pJM2cGiyQzfC6Gz0NsqA; path=/; expires=Wed, 23-Jul-25 19:42:43 GMT; domain=.stackexchange.com; HttpOnly; Secure; SameSite=None
set-cookie: _cfuvid=DdV8vZWKy.M0TrKxsV7lnozqa8UZXBDRDlstx5E66zc-1753297963459-0.0.1.1-604800000; path=/; domain=.stackexchange.com; HttpOnly; Secure; SameSite=None
server: cloudflare
content-encoding: gzip
Newest 'dynamic-sql' Questions - Database Administrators Stack Exchange
Skip to main content
Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeTeams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about TeamsQuestions tagged [dynamic-sql]
Constructing a query at runtime with string concatenation operations and executing the query from that string.
432 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
48
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....
1
vote
1
answer
154
views
How can I execute Openrowset in the named instance I am currently in?
I am running this openrowset query about jobs on my current server and I see that the result set is not correct.
I was expecting a bunch of jobs but I only get one.
when I run the following piece of ...
4
votes
2
answers
257
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
155
views
Need to modify Stored Procedure to create table in another database
We have a SQL database that is a secondary database or should I say a secondary replica in an AlwaysOn Availabiltity Group. As a result, the database is always a read-only database and therefore I can'...
0
votes
1
answer
158
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....
4
votes
1
answer
148
views
Are non-used CTEs never materialized in PostgreSQL 16?
I want to return my post rows in one of three sort orders, controlled by a sorting_param function parameter. The sorting is complex, doesn't lend itself to a simple ORDER BY CASE .... So I'm thinking ...
0
votes
1
answer
90
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 (...)
...
1
vote
1
answer
56
views
Rolling sum with partial value for last day
I can't figure out how to write a query that returns rolling sum by item based on rules in another table.
Below is a table that list in chronological order the stock value of an item on specific days.
...
0
votes
1
answer
88
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 ...
0
votes
3
answers
94
views
Dynamic column selection in a subquery
I have two tables, one containing polls and the other poll votes, like this (simplified):
CREATE TABLE IF NOT EXISTS polls (
id SERIAL PRIMARY KEY,
token VARCHAR(20)
);
CREATE TABLE IF NOT EXISTS ...
6
votes
1
answer
959
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 ...
2
votes
1
answer
249
views
Using a function as argument to GRANT fails with syntax error
I can't get GRANT to take current_database() as argument. These all fail with the same error:
GRANT ALL PRIVILEGES ON DATABASE current_database() to justintestin;
GRANT ALL PRIVILEGES ON DATABASE (...
0
votes
2
answers
54
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
18
views
How to format an array of identifiers?
I would like to write a function to define triggers. I would like to call it this way:
CALL make_mutable('mytable', '{"mycolumn3", "mycolumn4"}');
I think I need a dynamic ...
0
votes
1
answer
973
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 ...
- The Overflow Blog
-
-
- Featured on Meta
-
-
Related Tags
sql-server × 205
postgresql × 127
plpgsql × 68
t-sql × 56
stored-procedures × 49
sql-server-2016 × 26
functions × 24
oracle × 23
trigger × 21
pivot × 19
mysql × 18
plsql × 18
sql-server-2008-r2 × 18
sql-server-2012 × 17
sql-server-2014 × 14
parameter × 13
performance × 12
permissions × 11
sql-server-2008 × 11
view × 11
cursors × 10
linked-server × 9
sql-injection × 9
openrowset × 8
more related tags
Hot Network Questions
- Is buying random stocks and then selling off the ones that go down a good way to reduce capital gains tax?
- Did Germany declare the Donetsk People’s Republic to be a terrorist organization, at some point?
- Will a restless MCU survive long enough?
- Can I still get the pacifist ending if I use the fight option in a boss fight, but miss every time?
- Distance Between Subspaces
- Error on numerical integation
- Why do I get a INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY exception when my Apex code is without sharing?
- bootstrapping for variance estimation takes too long
- Is a chemistry-first technological paradigm as plausible as one focused on physics or biology?
- How to handle missing weather data (predictors) in production time series forecast with Prophet?
- Entity Framework - Is there a safety mechanism to prevent accidentally running Update-Database?
- Ubuntu gives the message "You are in emergency mode."
- Expected Sum of Remaining Dice After Removing Complete Sets
- Pourquoi "better to use ne alone" dans ce cas, "with savoir followed by an indirect question"?
- Must hospitals care for unidentifiable individuals indefinitely?
- Can one engage with physics (or science) without touching philosophy?
- A soviet sci-fi novel (novelette?) with frogs?
- Is it rude to make someone an academic reference without getting their permission first?
- Is there a formal threshold for when a variable is considered 'random' in statistics? What is it?
- Deployment fails with an error "Error (1): Unexpected end of JSON input"
- Etymology of the word skulduggery?
- Is there a smooth function approximating the minimum of a constant and a variable?
- Why does contact with the ground make my touch-activated LED brighter?
- When you view a historical event with an incorrect modern lens