Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

When ever I am trying to execute the below stored procedure I get this error:

Msg 4121, Level 16, State 1, Procedure create_or_replace_device, Line 46
Cannot find either column "xyz_account" or the user-defined function or aggregate "xyz_account.is_hex", or the name is ambiguous.



SQL
USE [abc]
GO
/****** Object:  StoredProcedure [dbo].[create_or_replace_device]    Script Date: 10/29/2013 12:26:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[create_or_replace_device] (
					  @iext_account_id varchar(30),
					  @iserial_number varchar(40),
					  @imanufacturer varchar(40),
					  @ihardware_type varchar(20),
					  @ioutlet varchar(25),
					  @iaction varchar(20),
					  @result int output,
					  @oSqlCode    int output,
					  @oSqlErrm     varchar(500) output) 
as
BEGIN	  
    declare @l_dev_rec_accountid    int
	declare @l_dev_rec_status    varchar(20)
	declare @l_dev_rec_devicetype    varchar(20)
	declare @l_dev_rec_outlet       varchar(25)

	declare @l_device_type   varchar(20);
	declare @l_status        varchar(20);
	declare @l_accountid     int;
	declare @l_networkid    int;
	declare @l_da_type int;
	
	declare @p_tmpRIGHTNOW datetime
	
	  
	set @p_tmpRIGHTNOW = getdate()
	set @oSqlCode = 0;
	set @oSqlErrm = '';
	set @result = 0; -- success

	IF (@iext_account_id is null) begin
		set @result = 2010; -- ext_account_id cannot be null
		return;
	END ;
	IF (@iserial_number is null) begin
		set @result = 2020; -- iserial_number cannot be null
		return;
	END ;

    IF (len(@iserial_number) > 12) begin
        set @result = 2021; -- Serial number maximum size exceeded
        return;
    end;
	  
    if (cast(upper(@iSerial_number) as varbinary) <> cast(@iSerial_number as varbinary) 
        or xyz_account.is_hex(@iSerial_number)= 0) begin
        set @result = 2021; -- Serial number is invalid.
        return;
    END ;
	IF (@imanufacturer is null) begin
		set @result = 2030; -- imanufacturer cannot be null
		return;
	END ;
	IF (len(@imanufacturer) > 40) begin
		set @result = 2031; -- Manufacturer maximum size exceeded
		return;
	END ;
	IF (@ihardware_type is null) begin
		set @result = 2040; -- ihardware_type cannot be null
		return;
	END ;
	IF (len(@ihardware_type) > 3) begin
		set @result = 2041; -- Hardware type maximum size exceeded
		return;
	END ;
	IF (len(@ioutlet) > 25) begin
		set @result = 2050; -- Outlet maximum size exceeded.
		return;
	END ;
	
	IF (@iaction is null) begin
		set @result = 2060; -- Action code is cannot be null
		return;
	END ;

	set @l_da_type = CASE @ihardware_type		WHEN 'STU' THEN 0	WHEN 'PRR' THEN 0	WHEN 'SCD' THEN 1 end
	IF @l_da_type is NULL begin
		set @result = 2041; -- hardware type is not valid
		return;
	END 

	begin try
		/* look for valid account */
		SELECT @l_accountid=accountid,@l_networkid=networkid FROM oact_tbl_accounts 
			WHERE extaccountid = @iext_account_id
		if @l_accountid is null begin
			  set @result = 2011; -- account not found.
			  return;
		end
		exec map2device_type @imanufacturer, @ihardware_type, @l_device_type output
		set @l_status = CASE @iaction WHEN 'i' THEN 'INACTIVE'	WHEN 'a' THEN 'ACTIVE' WHEN 'd' THEN 'REMOVED' END;

		IF (@l_status is NULL) begin
			set @result = 2061; -- action code is not valid
			return;
		END 

		SELECT @l_dev_rec_accountid=accountid, @l_dev_rec_status=status, 
			@l_dev_rec_devicetype = devicetype, @l_dev_rec_outlet=outlet
			FROM oact_tbl_devices		   WHERE deviceid = @iserial_number;
			
		if @l_dev_rec_accountid is not null begin
			IF @l_dev_rec_devicetype <> @l_device_type begin
				set @result =  2042;  -- device type must remain fixed for the life of the device.
				return;
			END;
			IF (@l_dev_rec_accountid <> @l_accountid OR @l_dev_rec_status <> @l_status
				OR isnull(@l_dev_rec_outlet,'') <> isnull(@ioutlet,''))  begin
				UPDATE oact_tbl_devices
					 SET  accountid = @l_accountid, status = @l_status, networkid = @l_networkid, outlet = @ioutlet,
					  updatedby = 'SMS Adapter', updatedon = getdate()
				   WHERE deviceid = @iserial_number;
				IF @l_dev_rec_status <> @l_status  begin
					update oact_tbl_digital_addresses set status = @l_status  WHERE deviceid = @iserial_number;
				END
			END ;
		end --end if 
		else begin
			
			exec add_device_and_da @l_accountid, @l_networkid,@iserial_number,@l_da_type,	@l_device_type,@ioutlet,@l_status
		end --end else
	end try
	begin catch
		set @result = 2990; -- oracle error updating device
		set @oSqlCode = error_number();
		set @oSqlErrm = error_message();
	end catch
end


Please help me with this.
Posted
Comments
Richard MacCutchan 29-Oct-13 5:05am    
You refer to xyz_account in the procedure, but where is it defined?

1 solution

if xyz_account.is_hex is a function then try prefixing dbo. to the function name.

C#
eg : dbo.xyz_account.is_hex
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900