-
Notifications
You must be signed in to change notification settings - Fork 0
/
Funcion y Procedure.sql
90 lines (66 loc) · 1.63 KB
/
Funcion y Procedure.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
--STORED PROCEDURE
USE [OBLIGATORIOBD2]
GO
/****** Object: StoredProcedure [dbo].[Cambiar_estacion_destino_de_linea] Script Date: 07/08/2022 20:11:18 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Cambiar_estacion_destino_de_linea]
@numero_linea int,
@codigo_estacion int
AS
DECLARE @parametro int
SET @parametro = 1
declare @Estacion_Final int
BEGIN
SELECT
@Estacion_Final=Codigo_Estacion_Final
FROM
LINEAS L
WHERE
Numero=@numero_linea
IF @Estacion_Final <> @codigo_estacion
UPDATE
LINEAS
SET
Codigo_Estacion_Final=@codigo_estacion, @parametro = 0
WHERE
Numero=@numero_linea
PRINT @parametro
END
GO
--FUNCION
USE [OBLIGATORIOBD2]
GO
/****** Object: UserDefinedFunction [dbo].[estacion_mas_trenes_fecha] Script Date: 07/08/2022 20:13:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[estacion_mas_trenes_fecha]
(@desde datetime, @hasta datetime)
RETURNS varchar(50)
AS
BEGIN
declare @descripcion varchar (50)
set @descripcion = ( SELECT top 1 e.Descripcion
from estaciones e
order By (select count(*)
from pasa p
where p.codigo_estacion = e.codigo and
p.fecha_hora >= @desde
and p.fecha_hora < @hasta) DESC)
RETURN @descripcion
END
GO