Script con dos variables

I am working on a project that I have to Write a simple script that creates two integer variables (one called Var1 and one called Var2),places the values 2 and 4 in them respectively, and then outputs the value of the two variables added together. Its kinda confusing for me since I am still learning writing scripts and batches. This is what I have so far:

    Declare @total
@Var1 var1 [= 2][,
@Var2 var2 [= 4]]]
 Set @total = @Var1 + @Var2

To be honest it kinda looks funny.I am just not understand to do this or if I am doing it right. In a way i dont think i should of even put set in there but wasnt understand how to add the two variables together at the end. I do know that a declare script is you can declare one or more variables at a time.So that is why I did the declare for this one.

preguntado el 08 de noviembre de 11 a las 13:11

What kind of SQL is this? MS SQL Server? -

Yes it is microsoft SQL server 2008 -

2 Respuestas

tratar:

DECLARE @a int
 SET @a=2
DECLARE @b int
 SET @b=2
DECLARE @Result int
 SET @Result=@a + @b

print @Result

respondido 08 nov., 11:17

 Declare @total int 
declare @Var1  int =2 --in sql 2008
declare @Var2  int =4 --in sql 2008
 Set @total = @Var1 + @Var2

or

 Declare @total int 
declare @Var1  
    set @var1=2 
declare @Var2
    set @var2=4
 Set @total = @Var1 + @Var2

respondido 08 nov., 11:17

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.