
sql - 1 SET statement for multiple variables like declare statement ...
Aug 18, 2014 · Is there a way to set all variables with one set statment, like you can with a declare statement? For example: Declare @Test VARCHAR(10), @Test2 VARCHAR(10), @T...
T-SQL, updating more than one variable in a single select
Jan 23, 2009 · You can use SELECT assignment to assign multiple variables. This code generates a single row of constants and assigns each to a variable. SELECT @var1 = 1, …
How to set value of multiple variable in T-SQL?
Aug 22, 2016 · Besides using SELECT @a = 10, @b = 'James', if you just want to set the values the first time they are declared, you can set the values of multiple variables when declaring …
Declare multiple variables in SQL - Stack Overflow
Feb 6, 2018 · You can't do that, but you can declare a variable as a table and put multiple values into the table. DECLARE @Planner AS TABLE (P VARCHAR(50)) INSERT @Planner …
How to set multiple local variables in one line using T-SQL?
Nov 25, 2011 · Works in SQL Server 2008 and up (you didn't specify which version of SQL Server....) Update: ok, so you're stuck on SQL Server 2005 - in that case, I believe this is the …
How do I DECLARE or SET multiple values in SQL?
Nov 14, 2022 · Issue: Cannot successfully add multiple values in the SET statement. Example of what I’m trying to complete: DECLARE @Beverage as varchar(1000) SET @Beverage = …
Set variable with multiple values and use IN - Stack Overflow
Sep 15, 2011 · DECLARE @Values varchar(1000); SET @Values = 'A, B, C'; SELECT blah FROM dbo.foo INNER JOIN dbo.SplitStrings(@Values, ',') AS s ON s.Item = foo.myField; On …
Setting two scalar variables in one SELECT statement?
Feb 3, 2012 · But this is invalid syntax. How do I set multiple scalar variables in one select statement? I can do: Declare @a int; Declare @b int; SET @a = (SELECT StartNum FROM …
How to set multiple values inside an if else statement?
IF ((SELECT COUNT(*) FROM table WHERE table.Date > '2016-03-20') > 10) BEGIN SET @test1 = 'test1' SET @test2 = 'test2' END ELSE BEGIN SET @test1 = 'testelse' SET @test2 …
case statement in SQL, how to return multiple variables?
Dec 2, 2011 · Depending on your use case, instead of using a case statement, you can use the union of multiple select statements, one for each condition. My goal when I found this question …