Quantcast
Channel: Chanmingman's Blog
Viewing all articles
Browse latest Browse all 1938

Declare A Variable and Assign A Value MySQL and MS SQL

$
0
0

This blog article shows you how to declare a variable and assign a value to it in MySQL. In Microsoft SQL to declare a variable and assign a value to it you do the following.

Declare @dt datetime

SELECT @dt = DATEADD(MONTH,-2, GETDATE());

SELECT @dt

{B076D3D1-C8F1-4C20-A7C0-BC20CA4558E9}

Unfortunately, I cannot find a way to declare a variable with specific data type in MySQL. I can only do the following.

SELECT @var_first := DATE_SUB(CURDATE(), INTERVAL 2 MONTH);

Also: Sql Server Generate Create Table Script Using Tsql

{DB35E438-FAF3-41BA-9051-7E90A0E1CD88}

It looks convenient but you will not know the data type of the variable @var_first.

Reference: https://stackoverflow.com/questions/3075147/select-into-variable-in-mysql-declare-causes-syntax-error?WT.mc_id=DP-MVP-36769


Viewing all articles
Browse latest Browse all 1938

Latest Images

Trending Articles



Latest Images