Consulta

17/11/2006 - 20:23 por Angee | Informe spam
BUenas Tardes de Nuevo,

Queria preguntarles otra cosa. Tengo un problema con una consulta.
Estoy haciendo lo siguiente:

select
substring(Tax_Id,1,1) as Tipo_Cliente,
'00000000' + substring(Tax_Id,2,13) as ID_Cliente,
'2' as Genero_Cliente ,
'VE' as Pais_Cliente,
ltrim(rtrim(Short_Name)) as Nombre_Cliente,
(select Sic_Code from dbo.RAW_CORP_Customer as
t1,RAW_CORP_ACTIVIDADECONOMICA as t2,RAW_CORP_Account as t3 where
t1.Sic_Code= t2.Sic_Code_Cosmos and t1.CustKey_Code=t3.CustKey_Code) as
Actividad_Cliente ,
'1'as Instrumento_Captacion,
'0' as F_M,
getdate() as Upd_Date
from RAW_CORP_Customer
where substring(Tax_Id,1,1) in ('z','F','G','I','J','P','R','V') and
substring(Tax_Id,1,1) <>'NULL'


Donde

(select Sic_Code from dbo.RAW_CORP_Customer as
t1,RAW_CORP_ACTIVIDADECONOMICA as t2,RAW_CORP_Account as t3 where
t1.Sic_Code= t2.Sic_Code_Cosmos and t1.CustKey_Code=t3.CustKey_Code) as
Actividad_Cliente ,

Me da un error debido a que el sub query me trae más de un registro. Y
entiendo que sea asi, pero no se como hacer para que me traiga el Sic_Code
por Código de CLiente(CustKey_Code)

Sic_Code es el código que tengo que reportar este se encuentra en la tabla
RAW_CORP_Customer pero debe relacionarse con cada cliente con la tabla
RAW_CORP_ACTIVIDADECONOMICA, es decir cada cliente debe tener su sic_Code
pero este debe estar contenido en la tabla RAW_CORP_ACTIVIDADECONOMICA. Me
pueden ayudar con este tema. No se como hacer para que me traiga solo el
sic_Code que corresponde


Muchas gracias por la ayuda que siempre me prestan
 

Leer las respuestas

#1 agile wannabe
17/11/2006 - 22:43 | Informe spam
Espero te sirva o te oriente esta forma de expresar el query

select substring(C.Tax_Id,1,1) as Tipo_Cliente,
'00000000' + substring(C.Tax_Id,2,13) as ID_Cliente,
'2' as Genero_Cliente ,
'VE' as Pais_Cliente,
ltrim(rtrim(C.Short_Name)) as Nombre_Cliente,
C.Sic_Code as Actividad_Cliente ,
'1'as Instrumento_Captacion,
'0' as F_M,
getdate() as Upd_Date
from RAW_CORP_Customer C
join RAW_CORP_ACTIVIDADECONOMICA t2
on
C.Sic_Code = t2.Sic_Code_Cosmos
join RAW_CORP_Account as t3
on
C.CustKey_Code=t3.CustKey_Code
where substring(Tax_Id,1,1) in ('z','F','G','I','J','P','R','V')
and
substring(Tax_Id,1,1) <>'NULL'

Revisa esta expresion:
substring(Tax_Id,1,1) <>'NULL'
una cadena de un caracter nunca será igual a la cadena 'NULL'
Para comparar contra NULO utiliza
expr IS NOT NULL

Preguntas similares