About 4,050,000 results
Open links in new tab
  1. ssis - How do I pass system variable value to the SQL statement

    I want to retrieve a System Variable and use it in an SQL INSERT. I want to retrieve the value of System:MachineName and use it in an insert statement. Using the statement INSERT INTO MYLOG (COL1) SELECT @[System::MachineName] gives the error Error: ..failed to parse.

  2. T-SQL 101: 98 Using System Variables and Functions in T-SQL

    Jan 25, 2025 · As well as the variables that you declare, SQL Server has a number of built-in system variables and some built-in system functions. The system variables are the ones with @@ at the start of their name. Here is an example that’s often used: SELECT @@VERSION; It is documented here. On my SQL Server 2022 system, the value returned is this:

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

    Nov 22, 2024 · To assign a value to a variable, use the SET statement. This is the preferred method of assigning a value to a variable. A variable can also have a value assigned by being referenced in the select list of a SELECT statement. To assign a variable a value by using the SET statement, include the variable name and the value to assign to the variable.

  4. sql server - sql use statement with variable - Stack Overflow

    I'm trying to switch the current database with a SQL statement. I have tried the following, but all attempts failed: To add a little more detail. EDIT: I would like to perform several things on two separate database, where both are configured with a variable. Something like this:

  5. sqlcmd Utility - Use Scripting Variables - SQL Server

    Nov 22, 2024 · Scripting variables can be defined explicitly by using the setvar command, or implicitly by using the sqlcmd -v option. This article also includes examples defining environmental variables at the Cmd.exe command prompt by using SET. The setvar command is used to define scripting variables.

  6. sql server - How can I do something like: USE @databaseName

    Sep 24, 2010 · DECLARE @DatabaseName NVARCHAR(max); SET @DatabaseName = 'MainDb' USE @DatabaseName. Wouldn't work. How to make it? Strongly related: How to use a variable for the database name in T-SQL? You'd have to use dynamic SQL if you want to do it dynamically like that.

  7. sqlcmd User Variables and Variable Precedence Examples

    Aug 24, 2017 · Sqlcmd allows the use of variables. It gives you the possibility to define variables on your scripts, on the sqlcmd console and also using the -v switch on the command line when executing sqlcmd. Additionally, sqlcmd can use environment …

  8. SQL SERVER – How to Set Variable and Use Variable in SQLCMD …

    Jun 28, 2013 · You can set scripting variables to dynamic variables and functions, but then the scripting variables have the same data type as the dynamic variables, and for all intents and purposes become the same, I.e., you can only use them as literal strings or numbers.

  9. Global Variables in MS SQL Server - GeeksforGeeks

    Aug 19, 2020 · Global variables are pre-defined system variables. It starts with @@. It provides information about the present user environment for SQL Server. SQL Server provides multiple global variables, which are very effective to use in Transact-SQL. The following are some frequently used global variables –. These are explained as following below.

  10. SQLCMD Variables in SQL Projects - SQL Server | Microsoft Learn

    SQLCMD variables are used in SQL projects to create dynamically replaceable tokens in SQL objects and scripts. The values of these variables are set at deployment time and can be used to dynamically set values in a SQL project.

Refresh