Top "Dynamic-sql" questions

Dynamic SQL is a technique using SQL (Structured Query Language) whose main difference from traditional SQL is that Dynamic SQL allows to build SQL statements dynamically at runtime, which eases the automatic generation and execution of program statements.

Declare Variable for a Query String

I was wondering if there was a way to do this in MS SQL Server 2005: DECLARE @theDate varchar(60) SET @theDate = …

sql sql-server sql-server-2005 tsql dynamic-sql
How to get sp_executesql result into a variable?

I have a piece of dynamic SQL I need to execute, I then need to store the result into a …

tsql dynamic-sql
Using a cursor with dynamic SQL in a stored procedure

I have a dynamic SQL statement I've created in a stored procedure. I need to iterate over the results using …

tsql stored-procedures dynamic-sql database-cursor
Why would someone use WHERE 1=1 AND <conditions> in a SQL clause?

Why would someone use WHERE 1=1 AND <conditions> in a SQL clause (Either SQL obtained through concatenated strings, either …

sql dynamic-sql
Drop all tables whose names begin with a certain string

How can I drop all tables whose names begin with a given string? I think this can be done with …

sql sql-server dynamic-sql
Dynamic SQL results into temp table in SQL Stored procedure

The code is as follows: ALTER PROCEDURE dbo.pdpd_DynamicCall @SQLString varchar(4096) = null AS Begin create TABLE #T1 ( column_1 varchar(10) , …

sql-server tsql dynamic-sql
Getting result of dynamic SQL into a variable for sql-server

Executing dynamic SQL as follows in Stored Procedure: DECLARE @sqlCommand nvarchar(1000) DECLARE @city varchar(75) SET @city = 'London' SET @sqlCommand = 'SELECT …

sql sql-server sql-server-2005 tsql dynamic-sql
How to use table variable in a dynamic sql statement?

In my stored procedure I declared two table variables on top of my procedure. Now I am trying to use …

sql sql-server sql-server-2008 dynamic-sql table-variable
Truncating all tables in a Postgres database

I regularly need to delete all the data from my PostgreSQL database before a rebuild. How would I do this …

postgresql plpgsql dynamic-sql truncate database-table
SQL update fields of one table from fields of another one

I have two tables: A [ID, column1, column2, column3] B [ID, column1, column2, column3, column4] A will always be subset …

sql postgresql sql-update dynamic-sql