Você está na página 1de 4

Declare @ndia int, @ldia nvarchar(10)

Set @ndia = 5
Set @ldia = case @ndia
when 1 then 'Lunes'
when 2 then 'Martes'
when 3 then 'Miercoles'
when 4 then 'Jueves'
when 5 then 'Viernes'
when 6 then 'Sabado'
when 7 then 'Domingo'
else 'Error'
end
print @ldia
Go

declare @ndia int, @ldia varchar(10)


set @ndia=5
set @ldia= case
when @ndia=1 then 'Lunes'
when @ndia=2 then 'Martes'
when @ndia=3 then 'Miercoles'
when @ndia=4 then 'Jueves'
when @ndia= 5 then 'Viernes'
when @ndia=6 then 'Sabado'
when @ndia=7 then 'Domingo'
else 'Error'
end
print @ldia

create table "alumnos"(nombre varchar(50), nota char(2), resultado


varchar(50));
select nombre,nota, resultado=
case nota
when 0 then 'libre'
when 1 then 'libre'
when 2 then 'libre'
when 3 then 'libre'
when 4 then 'regular'
when 5 then 'regular'
when 6 then 'regular'
when 7 then 'promocionado'
when 8 then 'promocionado'
when 9 then 'promocionado'
when 10 then 'promocionado'
end
from alumnos;

select nombre, nota, condicion=


case
when nota<4 then 'libre'
when nota >=4 and nota<7 then 'regular'
when nota>=7 then 'promocionado'
else 'sin nota'
end
from alumnos;
create table "Store_Information"(Store_Name nvarchar(50), Sales int, Txn_Date
date);
insert Store_Information(Store_Name, Sales, Txn_Date)
values ('Los Angeles', 1500, '1999/6/21')
insert Store_Information(Store_Name, Sales, Txn_Date)
values ('San Diego', 250, '1999/6/05')
insert Store_Information(Store_Name, Sales, Txn_Date)
values ('Boston', 700, '1999/6/08')
select * from Store_Information
go

SELECT Store_Name, CASE Store_Name


WHEN 'Los Angeles' THEN Sales * 2
WHEN 'San Diego' THEN Sales * 1.5
ELSE Sales
END
"Nuevas Ventas",Txn_Date
FROM Store_Information;

declare @contador int


set @contador = 0
while (@contador<10)
begin
set @contador = @contador + 1
if (@contador % 2 <> 0)
print 'Contador '+ cast(@contador as varchar)
end
go

declare @base int,@expon int, @contador int, @resul int


set @base = 5
set @expon =4
set @contador =1
set @resul = 1
while (@contador<=@expon)
begin
set @resul = @resul * @base
set @contador = @contador + 1
end

print 'Potencia: '+ cast(@base as varchar)+'^'+


cast(@expon as varchar)+' = '+cast(@resul as varchar)
go

declare @date time


set @date=getDate()
print @date

declare @dia int,@mes int, @anho int


set @dia= day(getdate())
set @mes= month (getdate())
set @anho= year (getdate())
print @dia
print @mes
print @anho
declare @fac int, @contador int, @resul int
set @fac = 5
set @contador =1
set @resul = 1
while (@contador<=@fac)
begin
set @resul = @resul * @contador
set @contador = @contador + 1
end
print 'Factorial: '+ cast(@fac as varchar)+'! ' + ' = '+cast(@resul as
varchar)

declare @numero1 int, @numero2 int, @resultado int


set @numero1=10
set @numero2=0
begin try
set @resultado= @numero1/@numero2
print @resultado
end try
begin catch
print 'error en la division'
PRINT ERROR_NUMBER()
PRINT ERROR_SEVERITY()
PRINT ERROR_LINE()
PRINT ERROR_MESSAGE()
end catch
go

declare @num1 int, @num2 int, @resultado int


set @num1=10
set @num2=0
begin try
if (@num2=0)
begin
raiserror('error xx',16,1)
end
end try
begin catch
PRINT ERROR_MESSAGE()
end catch

declare @base int, @altura int, @result int


set @base=10
set @altura=5
set @result = (@base * @altura)/2
print 'Area del triangulo es: '+ cast(@result as varchar)

declare @radio int, @mensaje int


set @radio=7
set @mensaje = 3/4 * power(@radio, 3) * 3.1416
print 'Volumen de la esfera: '+ cast(@mensaje as varchar)

declare @contador int


set @contador=1

while(@contador<=10)
begin
print 'Numero enteros: '+ cast(@contador as varchar)
set @contador =@contador + 1

end
go

Você também pode gostar