Estoy intentando meter una consulta grande de SQL en una variable de VB que despues es ejecutada en el proceso de la macro, pero creo que me pide unos saltos de linea, ó algo asi, la variable es de tipo string ya intente algunas cosas, pero incluso me toma las lineas de DECLARE como sentencias de VB parece.
Aqui les copio la parte que me da problemas:
Dim Connection1 As Object
Dim rst As Object
Dim rst1 As Object
Dim sql1 As String
Dim sql As String
sql = --USE SMSMexico_PRD
DECLARE @SalesCycleCode VARCHAR(12)
DECLARE @GeoTreeAreaCode VARCHAR(12)
/* Consulta de Actividad Switch Selling por Ciclo de Ventas y Zona
VCR, 2010-11-18, SR# 9,674,302 */
-- Configurar Código de Ciclo de Ventas
SET @SalesCycleCode = '201108'
-- Configurar Código Zona de Supervisión
SET @GeoTreeAreaCode = '840501'
CREATE TABLE ##Visitas
( CicloVentas VARCHAR(12)
, Territorio VARCHAR(12)
, CodigoCliente VARCHAR(12)
, NombreCliente VARCHAR(70)
, Estado VARCHAR(32)
, Canal VARCHAR(32)
, Subcanal VARCHAR(32)
, PotencialCliente VARCHAR(32)
, VisitActivityId UNIQUEIDENTIFIER
, CustomerId UNIQUEIDENTIFIER
)
CREATE TABLE ##Reporte
( CicloVentas VARCHAR(12)
, Territorio VARCHAR(12)
, CodigoCliente VARCHAR(12)
, NombreCliente VARCHAR(70)
, Estado VARCHAR(32)
, Canal VARCHAR(32)
, Subcanal VARCHAR(32)
, PotencialCliente VARCHAR(32)
, Subject VARCHAR(12)
, TIEMPOCATEGO VARCHAR(32)
, UTILIDCATEGO VARCHAR(1)
, PEDIDO VARCHAR(32)
, DISIPADO VARCHAR(1)
, ENTRENAMIENT VARCHAR(1)
, PAGOEMPLEADO VARCHAR(32)
, COMUNICPROMO VARCHAR(1)
, INVENTARIOS VARCHAR(1)
, REGISINVENTA VARCHAR(32)
, REGISVENTA VARCHAR(32)
, ALMACEN VARCHAR(1)
, OTRASCATEGO VARCHAR(1)
, CREDITOCAT VARCHAR(32)
, NEGOCIO VARCHAR(32)
, CREDITOCTES VARCHAR(1)
, DIASCREDITO VARCHAR(32)
, CARTEVENCID VARCHAR(1)
, INVENTFISICO VARCHAR(1)
, METODOEVALUA VARCHAR(32)
, CREDITOBANC VARCHAR(32)
, IDE VARCHAR(32)
, CONTADOR VARCHAR(1)
, VisitEndDateTime DATETIME
)
INSERT INTO ##Visitas
SELECT SalesCycleCode CicloVentas
, GeoTreeAreaCode Territorio
, CustomerCode CodigoCliente
, CustomerName NombreCliente
, CountryDescription Estado
, CustomerTypeDescription Canal
, CustomerTypeDetailDescription Subcanal
, IndustryClassificationLevelDescription PotencialCliente
, VisitActivityId
, CustomerId
FROM Customer
JOIN CustomerType ON Customer_CustomerTypeId = CustomerTypeId
JOIN CustomerTypeDetail ON Customer_CustomerTypeDetailId = CustomerTypeDetailId
JOIN CustomerAddress ON CustomerId = CustomerAddress_CustomerId
JOIN Address ON CustomerAddress_AddressId = AddressId
JOIN Country ON Address_CountryId = CountryId
JOIN IndustryClassificationLevel ON Customer_IndustryClassificationLevelId = IndustryClassificationLevelId
JOIN ( SELECT DISTINCT CustomerGeoTreeArea_CustomerId, GeoTreeAreaCode
FROM CustomerGeoTreeArea
JOIN GeoTreeArea ON CustomerGeoTreeArea_GeoTreeAreaId = GeoTreeAreaId
JOIN GeoTree ON GeoTreeArea_GeoTreeId = GeoTreeId
WHERE GeoTreeCode <> 'PWRSTMDZ'
AND GeoTreeAreaCode LIKE @GeoTreeAreaCode ) Territorio ON CustomerId = CustomerGeoTreeArea_CustomerId
JOIN ( SELECT SalesCycleCode, Visit_CustomerId, VisitActivityId
--• No Domestic Call Card (ORIGEN3)
FROM Journey, Visit, VisitActivity, SalesCycleActivity, SalesCycleActivityParameter, CallCard, SalesCycle
WHERE Visit_JourneyId = JourneyId
AND VisitId = VisitActivity_VisitId
AND VisitActivity_SalesCycleActivityId = SalesCycleActivityId
AND SalesCycleActivityId = SalesCycleActivityParameter_SalesCycleActivityId
AND SalesCycleActivityParameterValue = CAST(CallCardId AS VARCHAR(64))
AND SalesCycleActivity_SalesCycleId = SalesCycleId
AND SalesCycleCode = @SalesCycleCode
AND JourneyStatus = 'E'
AND VisitStatus = 'E'
AND CallCardCode = 'RIESGOMAY'
AND VisitActivityStatus = 'E' ) CallCards ON CustomerId = Visit_CustomerId
--WHERE CustomerCode = '0000102502'
ORDER BY 1, 2, 3
DECLARE VisitActivityCursor CURSOR FOR
SELECT VisitActivityId, CustomerId
FROM ##Visitas
DECLARE @VisitActivityId UNIQUEIDENTIFIER
DECLARE @CustomerId UNIQUEIDENTIFIER
OPEN VisitActivityCursor
FETCH VisitActivityCursor INTO @VisitActivityId, @CustomerId
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO ##Reporte
SELECT CicloVentas, Territorio,
CodigoCliente, NombreCliente,
Estado,
Canal, Subcanal,
PotencialCliente,
ISNULL(Answer_TIEMPOCATEGO.SubjectCode, ISNULL(Answer_UTILIDCATEGO.SubjectCode,
ISNULL(Answer_PEDIDO.SubjectCode, ISNULL(Answer_DISIPADO.SubjectCode,
ISNULL(Answer_ENTRENAMIENT.SubjectCode, ISNULL(Answer_PAGOEMPLEADO.SubjectCode,
ISNULL(Answer_REGISINVENTA.SubjectCode, ISNULL(Answer_REGISVENTA.SubjectCode,
ISNULL(Answer_ALMACEN.SubjectCode, ISNULL(Answer_OTRASCATEGO.SubjectCode,
ISNULL(Answer_CREDITOCAT.SubjectCode, ISNULL(Answer_NEGOCIO.SubjectCode,
ISNULL(Answer_CREDITOCTES.SubjectCode, ISNULL(Answer_DIASCREDITO.SubjectCode,
ISNULL(Answer_CARTEVENCID.SubjectCode, ISNULL(Answer_INVENTFISICO.SubjectCode,
ISNULL(Answer_METODOEVALUA.SubjectCode, ISNULL(Answer_CREDITOBANC.SubjectCode,
ISNULL(Answer_IDE.SubjectCode, ISNULL(Answer_CONTADOR.SubjectCode,
ISNULL(Answer_COMUNICPROMO.SubjectCode, Answer_INVENTARIOS.SubjectCode)))))))))))))))))))) ) SubjectCode,
RTRIM(ISNULL(Answer_TIEMPOCATEGO.AnswerValue, '')) TIEMPOCATEGO,
RTRIM(ISNULL(Answer_UTILIDCATEGO.AnswerValue, '')) UTILIDCATEGO,
RTRIM(ISNULL(Answer_PEDIDO.AnswerValue, '')) PEDIDO,
RTRIM(ISNULL(Answer_DISIPADO.AnswerValue, '')) DISIPADO,
RTRIM(ISNULL(Answer_ENTRENAMIENT.AnswerValue, '')) ENTRENAMIENT,
RTRIM(ISNULL(Answer_PAGOEMPLEADO.AnswerValue, '')) PAGOEMPLEADO,
RTRIM(ISNULL(Answer_COMUNICPROMO.AnswerValue, ''))COMUNICPROMO,
RTRIM(ISNULL(Answer_INVENTARIOS.AnswerValue, '')) INVENTARIOS,
RTRIM(ISNULL(Answer_REGISINVENTA.AnswerValue, '')) REGISINVENTA,
RTRIM(ISNULL(Answer_REGISVENTA.AnswerValue, '')) REGISVENTA,
RTRIM(ISNULL(Answer_ALMACEN.AnswerValue, ''))ALMACEN,
RTRIM(ISNULL(Answer_OTRASCATEGO.AnswerValue, '')) OTRASCATEGO,
RTRIM(ISNULL(Answer_CREDITOCAT.AnswerValue, '')) CREDITOCAT,
RTRIM(ISNULL(Answer_NEGOCIO.AnswerValue, '')) NEGOCIO,
RTRIM(ISNULL(Answer_CREDITOCTES.AnswerValue, ''))CREDITOCTES,
RTRIM(ISNULL(Answer_DIASCREDITO.AnswerValue, '')) DIASCREDITO,
RTRIM(ISNULL(Answer_CARTEVENCID.AnswerValue, ''))CARTEVENCID,
RTRIM(ISNULL(Answer_INVENTFISICO.AnswerValue, '')) INVENTFISICO,
RTRIM(ISNULL(Answer_METODOEVALUA.AnswerValue, '')) METODOEVALUA,
RTRIM(ISNULL(Answer_CREDITOBANC.AnswerValue, '')) CREDITOBANC,
RTRIM(ISNULL(Answer_IDE.AnswerValue, ''))IDE,
RTRIM(ISNULL(Answer_CONTADOR.AnswerValue, '')) CONTADOR