About 106,000 results
Open links in new tab
  1. How to set variable from a SQL query? - Stack Overflow

    When using SELECT, the variable is assigned the last value that is returned (as womp said), without any error or warning (this may cause logic bugs) The SET query returns error only if you DON'T put the …

  2. Variables (Transact-SQL) - SQL Server | Microsoft Learn

    Nov 18, 2025 · To assign a variable a value by using the SET statement, include the variable name and the value to assign to the variable. This is the preferred method of assigning a value to a variable.

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

    Jul 23, 2025 · Variable declaration in SQL Server is an essential requirement to handle and process data efficiently in SQL scripts, stored procedures, and functions. Variables can be declared by using …

  4. 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.

  5. How to Set a Variable from a SQL Query? Fixing Common Syntax …

    Nov 29, 2025 · This guide demystifies variable assignment from SQL queries. We’ll start by explaining what SQL variables are, walk through methods to set them across popular databases, dissect …

  6. SQL Variables: Basics and usage

    Nov 18, 2019 · SQL Server offers two different methods to assign values into variables except for initial value assignment. The first option is to use the SET statement and the second one is to use the …

  7. T-SQL Variables - Declare and Set variable

    By using variables, developers can write more flexible and dynamic SQL queries, enhancing the capability to handle data dynamically during runtime. Understanding how to declare, initialize, and …

  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 and …

  9. SQL Server SELECT INTO @Variable - GeeksforGeeks

    Jul 23, 2025 · Although there is no direct “SELECT INTO [variable]” syntax, you can use the “SET” statement to assign query results to variables. This gives you more flexibility and control when …

  10. SQL Variables: SQL Server Declare, Set and Select Variable - Guru99

    Jun 28, 2024 · SQL variables are the object which acts as a placeholder to a memory location. Various types of SQL Server variables, such as SQL Declare, Set, Select, Global, Local, etc.