El asunto es este tengo una tabla llamada ubigeo k consta de los sgtes campos: cod_dep char(2) cod_prov char(2) cod_dist char(2) nombre varchar(50) ejm: cod_dep cod_prov cod_dist Nombre 15 00 00 LIMA 15 01 17 LOS OLIVOS
Y DICHA tabla no tiene primary key,es decir no esta anexada a ninguna otra tabla,pero en las demas tablas que trabajo,,coloque una columna llamada ubigeo que es un char(6) y seria algo asi ubigeo 150000 150117
Lo que quiero es crear una funcion,para que me reconoxca los nombres de los ubigeos usando como parametro el ubigeo char(6), asi poder mostrarlo en alguna Vista en la cual crea conveniente,estaba haciendo este codigo,pero me bota el sgte error:
Msg 116, Level 16, State 1, Procedure obtenerDpto, Line 10 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Msg 116, Level 16, State 1, Procedure obtenerDpto, Line 12 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
AQUI LES DEJO LA FUNCION
create function obtenerDpto(@ubigeo char(6)) returns varchar(50) as begin declare @dep char(2) declare @prov char(2) declare @dist char(2) set @dep=(select substring(@ubigeo,1,2),(Select cod_dep , Nombre from Tb_Ubigeo where Cod_prov='00' and Cod_dist='00' and Cod_dep<>'00') from Tb_agente,Tb_Ubigeo where @dep=cod_dep and @ubigeo=ubigeo and @prov=cod_prov and @dist=cod_dist) return @dep return @prov return @dist end
la tabla agente que aperece,es una de las tablas que posee la columa ubigeo,por ello esta en la sentencia anterior
agradecere la ayuda que me puedan dar
|