CARVIEW |
Select Language
HTTP/2 200
date: Fri, 25 Jul 2025 02:54:55 GMT
content-type: text/html; charset=utf-8
cf-ray: 9648601719f7b22e-BLR
cf-cache-status: DYNAMIC
cache-control: private
set-cookie: prov=48d983a7-0239-4db0-8c73-e32fc041318d; expires=Sat, 25 Jul 2026 02:54:54 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: 9502aea6-2d76-483e-a936-469d3c5c714f
x-worker-origin-response-time: 515000000
x-dns-prefetch-control: off
set-cookie: prov=48d983a7-0239-4db0-8c73-e32fc041318d; Path=/; HttpOnly; Domain=stackexchange.com
set-cookie: __cf_bm=YsOasj8WgBCvFkjA9.B0FllPGacAQto0odnZmSiGMpo-1753412095-1.0.1.1-HQMzfta2XwSxgrl3pQ2I9Ftjx1iW2A9Jv.5Q_B1AEjMAsc7kS9PNr_x1raUigOf2MUyBMWGNV5n_XgYsConEEnvVUJpWbpzcpKGmbrOBh1E; path=/; expires=Fri, 25-Jul-25 03:24:55 GMT; domain=.stackexchange.com; HttpOnly; Secure; SameSite=None
set-cookie: _cfuvid=uSpozKbWG_01GO.1MMrNEkdSeGV0QgTRjeJAlW3_xAw-1753412095100-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
156
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
259
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
150
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
95
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
960
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
55
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
- How much of a really big a spaceship could a nuke take out?
- Distribution of a dot product of multinomial variables
- Can waves be seen?
- How do I implement this desired Excel data transformation?
- How to model This Twisted Torus?
- Access denied attempting to delete file on Windows Server
- Can one engage with physics (or science) without touching philosophy?
- What is the DC voltage during regenerative braking in a battery–inverter–induction motor system?
- Can a humanoid that fell supine and is then Levitated alter his orientation?
- leftmargin in enumerate
- Is a chemistry-first technological paradigm as plausible as one focused on physics or biology?
- Was Hermann Ganswindt's helicopter actually the first manned heavier-than-air motor-powered flight?
- How much time should I take for "self transfer" without checked-in baggage?
- Make a Mulenère encryption program
- Is the appearance of certain kinds of clouds at altitude of > 30000 feet a recent phenomenon?
- Did Germany declare the Donetsk People’s Republic to be a terrorist organization, at some point?
- Finding the value of collector resistor
- Why were two 2x6 boards installed on top of a window rough sill?
- Why 0.0 is printed as 0.00001 when rounding upward?
- Where did the name of Windows XP come from? Was it connected to the Cairo project?
- When was the last time all humans were on the ground not in the air?
- Did Denmark report that 64% Palestinian refugees from 1992 received serious fines or jail time?
- Heavy shelves, but not a center stud
- Are birth control pills classified as a carcinogenic at the same level as asbestos and tobacco?