
/****** Object:  StoredProcedure [dbo].[FDK_Link_Accounting]    Script Date: 06/17/2016 15:24:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

DROP PROCEDURE [dbo].[POS_Link_Inventory]
GO

CREATE PROCEDURE [dbo].[POS_Link_Inventory]
                 @base_datos VARCHAR(50),
	 		     @server     VARCHAR(40)
AS
BEGIN

  /*****************************************************************
   * POS_Link_Inventory
   * Proceso para enlazar esta base de datos con Inventory
   * Autor: Francis Bolaños Arias 23/06/2015 15:42:24 
   *****************************************************************/
   
  -- EXEC POS_Link_Inventory 'Inv_Karolas', ''
  -- EXEC POS_Link_Inventory 'Inventory', ''
  -- EXEC POS_Link_Inventory 'Inventory_Rest', ''
  -- EXEC POS_Link_Inventory 'Inventory_Inter', ''
  -- EXEC POS_Link_Inventory 'InnInv', ''
   
  SET NOCOUNT ON

  DECLARE @path VARCHAR(255),
	      @c    VARCHAR (8000)

  SELECT @base_datos = LTRIM(RTRIM(@base_datos)),
	     @server     = LTRIM(RTRIM(@server))
	     
  IF LEN(ISNULL(LTRIM(RTRIM(@server)), 0)) = 0 SET @server = @@SERVERNAME

  IF @@SERVERNAME = @server
     SELECT @path = @base_datos + '..'
  ELSE 
     SELECT @path = @server + '.' + @base_datos + '.dbo.'
     
  -- STOKTABL
  IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[STOKTABL]') AND OBJECTPROPERTY(id, N'IsView') = 1)
     DROP VIEW [dbo].[STOKTABL]

  SET @c = 'CREATE VIEW dbo.STOKTABL AS SELECT * FROM ' + @path + 'STOKTABL'
  EXECUTE(@c)
  
  -- STOKEMPR
  IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[STOKEMPR]') AND OBJECTPROPERTY(id, N'IsView') = 1)
     DROP VIEW [dbo].[STOKEMPR]

  SET @c = 'CREATE VIEW dbo.STOKEMPR AS SELECT * FROM ' + @path + 'STOKEMPR'
  EXECUTE(@c)
  
  -- STOKMONE
  --IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[STOKMONE]') AND OBJECTPROPERTY(id, N'IsView') = 1)
  --   DROP VIEW [dbo].[STOKMONE]

  --SET @c = 'CREATE VIEW dbo.STOKMONE AS SELECT * FROM ' + @path + 'SICLAMON'
  --EXECUTE(@c)
  
END

