「SQLServer」DECLAREで変数を定義する

環境
Windows10 64bit
microsoft SQLServer 2019

書式
DECLARE @変数名 データの型;
set @変数名=値
PRINT @変数名

1.int型変数を定義します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SQL構文
DECLARE @res int;
SET @res = 11+22;
PRINT @res;
実行結果
33
SQL構文 DECLARE @res int; SET @res = 11+22; PRINT @res; 実行結果 33
SQL構文
DECLARE @res int;
SET @res = 11+22;
PRINT @res;
実行結果
33

2.var型変数を定義します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
SQL構文
DECLARE @str VARCHAR(50);
SET @str = 'study skill';
PRINT @str;
実行結果
study skill
SQL構文 DECLARE @str VARCHAR(50); SET @str = 'study skill'; PRINT @str; 実行結果 study skill
SQL構文
DECLARE @str VARCHAR(50);
SET @str = 'study skill';
PRINT @str;
実行結果
study skill

 

SQLServer

Posted by arkgame