About 358,000 results
Open links in new tab
  1. DECLARE @local_variable (Transact-SQL) - SQL Server

    Nov 18, 2025 · Variables are declared in the body of a batch or procedure with the DECLARE statement and are assigned values by using either a SET or SELECT statement. Cursor …

  2. SQL Declare Variable Code Examples - SQL Server Tips

    Oct 30, 2025 · Learn how to define and use variables in SQL Server code with these many different SQL Declare Variable code examples.

  3. How to Declare a Variable in SQL Server? - GeeksforGeeks

    Jul 23, 2025 · We cannot declare a variable and directly assign it the result from a subquery in the DECLARE statement in SQL Server. However, we can set a variable with a subquery after it …

  4. How do I declare and assign a variable on a single line in SQL

    DECLARE myVariable nvarchar[MAX] = "hello world". Bonus points if you show me how to encode a quote in the string. The string delimiter in SQL Server is ', not ". Here goes: You will …

  5. SQL Variables: Basics and usage

    Nov 18, 2019 · The DECLARE statement is used to declare a variable in SQL Server. In the second step, we have to specify the name of the variable. Local variable names have to start …

  6. SQL Server: Declare Variables - TechOnTheNet

    Learn how to declare variables in SQL Server (Transact-SQL) with syntax and examples. In SQL Server (Transact-SQL), a variable allows a programmer to store data temporarily during the …

  7. SQL DECLARE Variable: Complete Guide | Examples in All 5 …

    Dec 6, 2025 · Therefore, this guide will explain everything you need to know about SQL DECLARE Variable across major databases in SQL Server, MySQL, PostgreSQL, and Oracle.

  8. How to Declare and Assign Value to a Variable in SQL Server

    May 2, 2025 · Understanding how to declare and assign values to variables is essential for writing efficient and maintainable SQL scripts. In this guide, we will explore different ways to declare …

  9. T-SQL Variables - Declare and Set variable

    Variables are a fundamental aspect of SQL Server programming, enabling developers to write more efficient, dynamic, and readable SQL scripts. Understanding how to properly declare, …

  10. SQL Server SELECT INTO @variable: How to Assign Scalar and …

    Jan 6, 2026 · SQL Server SELECT INTO @variable: How to Assign Scalar and Table Variables in Stored Procedures (Examples) In SQL Server, variables play a critical role in storing …