About 8,460 results
Open links in new tab
  1. Declare variable in table valued function - Stack Overflow

    Aug 28, 2023 · declare @Var int. set @Var = 10. insert into @T(ColName) values (@Var) return.

  2. SQL Server: CREATE FUNCTION with declare variables inside

    Jun 21, 2017 · In this function, I need to define some variables and then use it in the SELECT. SQL looks like below: CREATE FUNCTION [dbo].[MyFussnction] ( @path [nvarchar](10) ) RETURNS TABLE BEGIN DECLARE @xx varchar(50); SET @xx = 'Windows%'; RETURN SELECT * FROM MyTable WHERE DataPath LIKE @path AND XX LIKE @xx; END

  3. declare variable in a sql function - Stack Overflow

    Nov 18, 2010 · In SQL Server you can't declare variables inside of an inline table-Valued function. You'll need to create a multi-statement table valued function if you really need to declare variables in it. You would do something like this: @CLIENTPK_NEW …

  4. SQL Declare Variable Code Examples - MSSQLTips.com - SQL

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

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

    Aug 23, 2024 · 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 the DECLARE statement and then values set to …

  6. SQL Variable Examples in Stored Procedures, Functions, Scripts, …

    Mar 18, 2022 · To declare a variable, we need to use the word DECLARE and then specify the name with the @ prefix and then the data type. The following example shows how to declare a variable of type smallint. DECLARE @myvariable smallint

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

    Nov 22, 2024 · The DECLARE statement initializes a Transact-SQL variable by: Assigning a name. The name must have a single @ as the first character. Assigning a system-supplied or user-defined data type and a length. For numeric variables, a precision and scale are also assigned. For variables of type XML, an optional schema collection might be assigned.

  8. sql server - declare table variable inside function - Database ...

    Aug 20, 2019 · You need to declare a table variable with the same shape as the TVF result, then use INSERT INTO not SELECT INTO, and remember to add brackets/parentheses to the end of the function name when invoking it, i.e. Foo() not just Foo:

  9. How to Declare a Variable in SQL? - GeeksforGeeks

    Dec 30, 2024 · In this article, we will explain various methods and best practices for declaring variables in SQL, along with the syntax and examples, that help us write more dynamic and effective queries. 1. Using the SET Command.

  10. A Guide To the SQL DECLARE Statement - dbvis.com

    Dec 12, 2024 · In SQL Server, the DECLARE statement allows you to declare variables in a transaction or the body of a batch or procedure. You can then assign values to these variables by using either a SET or SELECT statement. After declaration, all variables are initialized as NULL, unless a specific value is provided.

Refresh