Home > SQL Server > SQL SERVER – Declare Mulitple Variables in Single Line

SQL SERVER – Declare Mulitple Variables in Single Line


This may be a simple thing, but sometime new developers are difficult to find this information readily. So, thought of adding it in this website.

Question
How to declare and initialize variables in single or multiple lines?

Answer:

Declaring variables – Multiple lines

DECLARE @int_i AS INT;
DECLARE @chr_Name AS VARCHAR(50);

Declare and Initialize variables – Multiple lines

DECLARE @int_i AS INT = 1;
DECLARE @chr_Name AS VARCHAR(50) = ‘Test’;

Declare variables in single line

DECLARE @int_i AS INT, @chr_Name AS VARCHAR(50);

Declare and Initialize variables in single line

DECLARE @int_i AS INT = 1, @chr_Name AS VARCHAR(50) = ‘Test’;

That is it, You have learned to declare and initialize variables in MS SQL Server.

Advertisements
Categories: SQL Server Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: