About 58,300 results
Open links in new tab
  1. sql server - Create A View With Dynamic Sql - Stack Overflow

    You can do this by double nesting the dynamic SQL statements then: begin tran declare @sql nvarchar(max) = N'use [AdventureWorks2012]; exec (''create view Test as select * from sys.databases'')'; exec (@sql); select * from AdventureWorks2012.sys.views where name = …

  2. Dynamic SQL with variables inside a view (SQL Server)

    Solution: I just ended up having it drop the old view and recreate a new view (using dynamic sql) in a Stored Procedure. When that value is changed I will just call the SP which will update the views to point to the correct databases.

  3. Dynamic SQL in SQL Server - GeeksforGeeks

    Dec 27, 2023 · Dynamic SQL helps to create flexible, adaptable, and reusable SQL queries that can be applied to different scenarios and situations in fetching data from SQL Server. Some of the general uses of Dynamic SQL are given below:

  4. CREATE VIEW SQL Server Examples with T-SQL and SSMS

    Mar 7, 2023 · A view in SQL is a virtual table based on the result of a SELECT statement from one or more tables. It provides a way to simplify complex queries, hide data complexity, and provide security by restricting access to specific columns of a table.

  5. Create dynamic view - Microsoft Q&A

    Sep 22, 2021 · It is not possible to have a view, which dynamically selects data from databases with varying names. Why that design with one database per month? I would put all data in one database/one table; SQL Server scales well.

  6. SQL Server Dynamic SQL - SQL Server Tutorial

    For example, you can use the dynamic SQL to create a stored procedure that queries data against a table whose name is not known until runtime. Creating a dynamic SQL is simple, you just need to make it a string as follows: Code language: SQL (Structured Query Language) (sql)

  7. Dynamic SQL - GeeksforGeeks

    Jan 15, 2025 · In this article, we will explain the concept of Dynamic SQL, its syntax, and how it differs from static SQL. We’ll learn how to construct and execute dynamic queries in SQL Server, along with examples and outputs to demonstrate its practical applications

  8. sql server - Create A View Using Dynamic Sql - Database …

    I've tried four different ways to create this view without success: My first thought was to simply set the database context and then create the view in one script. Unfortunately, this didn't work because CREATE VIEW must be the first statement in its query block (details). USE [' + @databaseName + '] CREATE VIEW.

  9. Views in SQL Server with [Examples] - Shekh Ali's Blog

    Jun 22, 2021 · In SQL, Views are virtual tables that give a simplified and customized view of data from one or multiple database tables. They are similar to a table with rows and columns but do not store actual data. This article will cover the different types of …

  10. sql server - Use Dynamic SQL To Create View From Cursor

    Aug 16, 2017 · Here's a sample fiddle showing the results: declare @sql varchar(max), @cr char(1) set @cr = char(10) Set @sql = isnull(@sql,'') + @cr + case when @sql is NULL then 'create view dbo.Test as ' else 'union all ' end + @cr + 'SELECT x from mytable1 ...'

Refresh