· 8 years ago · Feb 07, 2018, 11:22 PM
1USE [Calderas]
2GO
3
4/****** Object: Table [dbo].[ClasificacionProducto] Script Date: 07/02/2018 06:13:58 p.m. ******/
5SET ANSI_NULLS ON
6GO
7
8SET QUOTED_IDENTIFIER ON
9GO
10
11CREATE TABLE [dbo].[ClasificacionProducto](
12 [Id_ClaProducto] [nchar](2) NOT NULL,
13 [Descripcion] [nvarchar](25) NOT NULL,
14 CONSTRAINT [PK_ClasificacionProducto] PRIMARY KEY CLUSTERED
15(
16 [Id_ClaProducto] ASC
17)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
18UNIQUE NONCLUSTERED
19(
20 [Descripcion] ASC
21)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
22) ON [PRIMARY]
23
24GO
25
26alter procedure usp_NuevaClasificacionProducto
27--Declaro las variables a ingresar a la tabla
28@Codigo nchar(2),
29@Descripcion varchar(25)
30as
31 begin
32 SET NOCOUNT ON
33 begin tran e
34 begin try
35 --Evito duplicidad validando la existencia de la Descripción
36 if NOT EXISTS (SELECT Descripcion FROM ClasificacionProducto where Descripcion= @Descripcion)
37 begin
38 --Al guardar las variables esten en mayúscula y sin espacios
39 set @Codigo = upper(Rtrim(ltrim(@Codigo)))
40 set @Descripcion = upper(RTRIM(ltrim(@Descripcion)))
41 --Inserto las variables
42 insert into ClasificacionProducto(Id_ClaProducto, Descripcion )
43 values(@Codigo , @Descripcion)
44 print 'Datos ingresados' + @Descripcion + @Codigo
45 end
46 commit tran e
47 end try
48 begin catch
49 --indico que si hay nulos en decripción o código no se inserte
50 if @Descripcion is null or @Codigo is null
51 print 'Ingresar Descripción o Código '
52 rollback
53 end catch
54 SET NOCOUNT OFF
55 end
56go