declare @busca UD_IDCORPORATIVO
declare @id UD_IDCORPORATIVO
declare @sku UD_IDCORPORATIVO
declare @BUYCOD char(20)
declare @CURYID ud_curyid
declare @STDCOST ud_costo
          
set @busca='100052'


declare @fi datetime 
declare @ff datetime 
set @fi=getdate()
select @fi

select @id=INVTIDSKU, @BUYCOD=BUYCOD,@CURYID=CURYID,@STDCOST=STDCOST
		 from in_vendorinvt where VENDIDSS='20100052050' AND SITEID='00057' and buycod=@busca
if( @id is not null)	--lo encontro
	begin
		set @sku=@id
		select @id,@BUYCOD,@CURYID,@STDCOST,'proveeedor'
	end
else			--no lo encontro, busca en codigo barra
	begin
		select @id=INVTIDSKU from in_inventoryalter where INVTIDBARR=@busca
		if( @id is not null)	--lo encontro
		begin
			set @sku=@id
			select @id=INVTIDSKU, @BUYCOD=BUYCOD,@CURYID=CURYID,@STDCOST=STDCOST
			 from in_vendorinvt where VENDIDSS='20100052050'  and INVTIDSKU=@sku AND SITEID='00057'
			select @id,@BUYCOD,@CURYID,@STDCOST,'alternativo'
		end
		else		--no lo encontro en alternativo, buscalo en inventorydat
		begin		
			select @id=INVTIDSKU from in_inventory where INVTIDSKU =@busca
			if( @id is not null)	--lo encontro
			begin
				set @sku=@id
				select @id=INVTIDSKU, @BUYCOD=BUYCOD,@CURYID=CURYID,@STDCOST=STDCOST
				 from in_vendorinvt where VENDIDSS='20100052050'  and INVTIDSKU=@sku AND SITEID='00057'
				
				select @id,@BUYCOD,@CURYID,@STDCOST,'inventory'
			end
		end			
end

set @ff=getdate()
select @ff
select @ff-@fi


--select * from in_vendorinvt where INVTIDSKU <>BUYCOD  
select * from in_inventoryalter where INVTIDSKU='100080'