dbo.DR_CONSTANTEOLD

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

3
Name Data Type Length Description
@Constante varchar 50
@Country_code varchar 2
@Cliente int 4

SQL Script

Copy
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE OR ALTER PROCEDURE  dbo.DR_CONSTANTEOLD
@Constante varchar(50), @Country_code varchar(2), @Cliente int

AS

BEGIN
 SET NOCOUNT ON;

 DECLARE @qConstante varchar(50)
 DECLARE @qcountry_code varchar(2)
 DECLARE @qcliente varchar(10)
 DECLARE @qtexto_idioma_1 varchar(8000)
 DECLARE @qtexto_idioma_2 varchar(8000)
 DECLARE @qtexto_idioma_3 varchar(8000)
 DECLARE @qverificado tinyint
 DECLARE @qrows int = 0
 DECLARE @SQLString nvarchar(4000)
 

 /*
  SET @SQLString = 'DECLARE GDL_Constantes Cursor FOR SELECT ' + @qConstante + ' = constante, ' + @qcountry_code + '= country_code '
  SET @SQLString = @SQLString + @qcliente + '= cliente, ' + @qtexto_idioma_1 + '= texto_idioma_1 '
  SET @SQLString = @SQLString + @qtexto_idioma_2 + '= texto_idioma_2, ' + @qtexto_idioma_3 +' = texto_idioma_3 '
  SET @SQLString = @SQLString + 'FROM gdl_constantes WHERE constante = ''' + @Constante + '''' 
  */

 
 SET @SQLString = 'DECLARE GDL_Constantes Cursor FOR SELECT * FROM gdl_constantes WHERE constante = ''' + @Constante + '''' 
 

 IF EXISTS (SELECT * FROM gdl_constantes
 WHERE constante = @Constante
 AND country_code = @Country_code
 AND cliente = @Cliente)

  BEGIN
   SET @SQLString = @SQLString + ' AND country_code = ''' + @Country_code + ''''
   SET @SQLString = @SQLString + ' AND cliente = ' + CONVERT(varchar(10),@Cliente)
  END
 ELSE
  BEGIN
   IF EXISTS (SELECT * FROM gdl_constantes
   WHERE constante = @Constante
   AND country_code = @Country_code
   AND cliente = 0)

    BEGIN
     SET @SQLString = @SQLString + ' AND country_code = ''' + @Country_code + '''' + ' AND cliente = 0'
    END
   ELSE
    BEGIN
     SET @SQLString = @SQLString + ' AND country_code = ''' + 'XX' + '''' + ' AND cliente = 0'
    END
  END

  exec sp_executesql @SQLString
  
  Open GDL_Constantes

   Fetch NEXT FROM GDL_Constantes INTO @qConstante, @qcountry_code, @qcliente,@qtexto_idioma_1,@qtexto_idioma_2,@qtexto_idioma_3,@qverificado

   While (@@FETCH_STATUS <> -1)
   BEGIN
    /* si las variables son null inserto la constante para country XX y cliente 0 */
    set @qrows = @qrows + 1
    FETCH NEXT FROM GDL_Constantes INTO @qConstante, @qcountry_code, @qcliente,@qtexto_idioma_1,@qtexto_idioma_2,@qtexto_idioma_3,@qverificado
   END

  CLOSE GDL_Constantes
 DEALLOCATE GDL_Constantes


 if (@qrows = 0) 
  BEGIN
   INSERT INTO gdl_constantes(constante,country_code,cliente,texto_idioma_1,texto_idioma_2,texto_idioma_3,verificado)
   VALUES (@Constante, 'XX',0,@Constante,@Constante,@Constante,0) 

   SET @qConstante = @Constante
   SET @qcountry_code = 'XX'
   SET @qcliente= 0
   SET @qtexto_idioma_1 =  @Constante
   SET @qtexto_idioma_2 =  @Constante
   SET @qtexto_idioma_3 =  @Constante
   SET @qverificado =  0
  END
  


SELECT @qConstante as constante, @qcountry_code as country_code,@qcliente as cliente, @qtexto_idioma_1 as texto_idioma_1,@qtexto_idioma_2 as texto_idioma_2, @qtexto_idioma_3 as texto_idioma_3 , @qverificado as verificado
--@SQLString AS SQLString, 
-- SELECT @Constante as constante, 'XX' as country_code,0 as cliente, @Constante as texto_idioma_1,@Constante as texto_idioma_2, @Constante as texto_idioma_3 


END

GO

Depends On

1

Used By

No items found