Ver Mensaje Individual
  #4 (permalink)  
Antiguo 12/08/2011, 16:14
Crack_x01
 
Fecha de Ingreso: agosto-2011
Ubicación: Edo. de Mexico
Mensajes: 12
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Crear Tabla temporal en SQL 2005 desde una macro en Excel (VB) y consultar

No, no funciono crear la tabla con sesiones multiples, me sigue mandando el mismo error:

Run-Time error '9'
Script Out Of Range

Lo manda en esta linea:

Sheets(Data).Range(Chr(i + 65) & F + 1).Value = rst1.Fields(i).Name

La cual es la primer linea de insercion de datos en la hoja de excel, despues de llamar la 1° consulta de la tabla temporal, lo raro es que esa parte del codigo lo uso en muchas otras macros que hacen consultas a tablas fisicas y no presenta error alguno.

les envio tambien el contenido del textbox (el script) que llama la variable "sql" la cual crea la tabla tamporal.


SELECT DISTINCT GeoTreeAreaCode, CustomerCode,
ISNULL(CountryDescription, 'SIN ESTADO') Estado,
ISNULL(AddressLevel1Description, 'SIN MUNICIPIO') Municipio,
ISNULL(AddressLevel2Description, 'SIN LOCALIDAD')Localidad,
ISNULL(CustomerTypeDescription, 'SIN CANAL') Canal,
ISNULL(CustomerTypeDetailDescription, 'SIN SUBCANAL') SubCanal,
ISNULL(TradeCategoryDescription, 'SIN TIPO DE NEGOCIO') TipoNegocio,
ISNULL(SubTradeCategoryDescription, 'SIN SUBTIPO DE NEGOCIO') SubTipoNegocio,
"HET" =
CASE
WHEN CustomerRegisteredName LIKE '%OXXO%' THEN 'OXXO'
WHEN CustomerRegisteredName LIKE '%ELEVEN%' THEN 'SEVEN'
WHEN CustomerRegisteredName LIKE '%CORPORACION ALIMENTARIA%' THEN 'SEVEN'
WHEN CustomerRegisteredName LIKE '%CIRCULO%' THEN 'CIRCULO'
WHEN CustomerRegisteredName LIKE '%CCK%' THEN 'CIRCULO'
WHEN CustomerRegisteredName LIKE '%OPERADORA RIO COLORADO%' THEN 'CIRCULO'
WHEN CustomerRegisteredName LIKE '%ADMINISTRADORA DEL COLORADO%' THEN 'CIRCULO'
WHEN CustomerRegisteredName LIKE '%EXTRA%' THEN 'EXTRA'
ELSE 'OTRO'
END,
"CPW" =
CASE
WHEN CustomerIndustryVolume > 25 THEN 25
WHEN CustomerIndustryVolume IS NULL THEN 0
ELSE CustomerIndustryVolume
END,
"TIPO" =
CASE
WHEN GeoTreeAreaCode BETWEEN '410000' AND '899999' THEN 'VTA'
WHEN GeoTreeAreaCode BETWEEN '310000' AND '399999' THEN 'UNI'
ELSE 'CAD'
END,
ISNULL(IndustryClassificationLevelCode, 'SIN') Potencial,
ISNULL(CustomerIndustryVolume, 0)CustomerIndustryVolume,
ISNULL(CustomerInternalVolume, 0) CustomerInternalVolume
INTO ##CtesTmp
FROM Customer
LEFT OUTER JOIN IndustryClassificationLevel ON Customer_IndustryClassificationLevelId = IndustryClassificationLevelId
JOIN CustomerGeoTreeArea ON CustomerId = CustomerGeoTreeArea_CustomerId
JOIN GeoTreeArea ON CustomerGeoTreeArea_GeoTreeAreaId = GeoTreeAreaId
-- AND GeoTreeAreaCode LIKE '760%'
JOIN GeoTree ON CustomerGeoTreeArea_GeoTreeId = GeoTreeId
AND GeoTreeCode IN ('VOLGEOTREE', 'MERCADEODET', 'MERCADEOMAY','MERCHRETAIL','MERCHWS','MERCHMDZ')
JOIN CustomerAddress ON CustomerId = CustomerAddress_CustomerId
AND CustomerAddressCode IN ('MAIN')
JOIN Address ON CustomerAddress_AddressId = AddressId
LEFT OUTER JOIN Country ON Address_CountryId = CountryId
LEFT OUTER JOIN AddressLevel1 ON Address_AddressLevel1Id = AddressLevel1Id
LEFT OUTER JOIN AddressLevel2 ON Address_AddressLevel2Id = AddressLevel2Id
LEFT OUTER JOIN TradeCategory ON Customer_TradeCategoryId = TradeCategoryId
LEFT OUTER JOIN SubTradeCategory ON Customer_SubTradeCategoryId = SubTradeCategoryId
LEFT OUTER JOIN CustomerType ON Customer_CustomerTypeId = CustomerTypeId
LEFT OUTER JOIN CustomerTypeDetail ON Customer_CustomerTypeDetailId = CustomerTypeDetailId
WHERE CustomerStatus = 'A'
-- AND CustomerCode NOT LIKE 'MDZ%'
ORDER BY GeoTreeAreaCode, Customercode