varchar in sql code example

Example 1: varchar max length

65,535

The length can be specified as a value from 0 to 65,535. 
The effective maximum length of a VARCHAR is subject to 
the maximum row size (65,535 bytes, which is shared among all columns) 
and the character set used.

Example 2: char varchar nvarchar sql

1. char - is the SQL-92 synonym for character. Data is padded with blanks/spaces to fill the field size. Fixed length data type.
2. nchar - is the SQL-92 synonym for national char and national character. Fixed length data type.
3. varchar - is the SQL-92 synonym for character varying. Variable length data type.
4. nvarchar - is the SQL-92 synonym for national char varying and national character varying. Variable length data type.

Example 3: var in sql

One way of doing this is to use database variables

create table testcalc (
   id int(11) not null auto_increment,
   num1 int(11) default null,
   num2 int(11) default null,
   num3 int(11) default null,
   num4 int(11) default null,
   primary key(id)
);

insert into testcalc values
(default, 1, 2, 3, 4),
(default, 5, 10, 15, 20);
Then you can get the same results as in your example by storing the calculation results in variable syntax like this

@youVar := (calc) as resultName01
Then it will be available to following calculations to use like this

(@youVar + newCalc) as resultName02
We can apply it to your example like this

select
   id,
   num1,
   num2,
   num3,
   num4,
   @1plus2 := (num1 + num2) as 1plus2,                   # create var01
   @1plus2mult3 := (@1plus2 * num3) as 1plus2mult3,      # create var02 using var01
   @sumOfCalc := (@1plus2 + @1plus2mult3) as sumOfCalc   # create var03 using var01 and var02
from testcalc;