必须声明一个标量变量“@ code_value” [英] Must declare a scalar variable "@code_value"

查看:77
本文介绍了必须声明一个标量变量“@ code_value”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试保存此程序时,我收到错误



必须声明SCALAR VARIABLE@code_value





When try to save this procedure I am getting the error

MUST DECLARE A SCALAR VARIABLE "@code_value"


ALTER PROCEDURE p_trans
	(
	@date datetime,
	@ref varchar(30)= null,
	@dr_amt money=0,
	@cr_amt money =0,
	@posted_to integer,
	@id char(1),
	@doc_no integer = null,
	@narr varchar(150) = null
	)
AS
	DECLARE @ll_doc integer
	DECLARE @ret integer
	DECLARE @code_value integer
	
	
	/* Get the selected cash/ bank account:
	The user makes a selection from selection.aspx and 
	tbl_section is update with the code_value
	*/
	SELECT @code_value = Selection 
	FROM tbl_selection
	
	BEGIN TRANSACTION
	
	IF isnull(@doc_no,0)=0
	--- INSERT---
	
	BEGIN
	--- Safe Guard: Check if transaction with same ref# exists. If so do not insert -----
	
		SELECT @ret=count(*) 
		FROM tr_header 
		WHERE ref=@ref
		
		IF @ret>0
		BEGIN
		--- raise error(5300,1,16)
			GOTO doerror
		END
		
		SELECT @ll_doc=isnull(max(doc_no),0)+1 
		FROM tr_header
		
		IF @@ERROR != 0
		BEGIN
			GOTO doerror
		END
	END
	
	ELSE
	---------- UPDATE----------
	BEGIN
		
		SET @ll_doc=@doc_no
		
		DELETE FROM transactions 
		WHERE doc_no=@doc_no
	
		IF @@ERROR != 0
		BEGIN
			GOTO doerror
		END
	END
	BEGIN
	INSERT INTO tr_header (id, date, ref, doc_no, narr)
	VALUES (@id,isnull(@date,getdate()),@ref,@ll_doc,@narr)
	
	IF @@ERROR != 0
	BEGIN
		GOTO doerror
	END
	INSERT INTO transactions (doc_no, dr_amount, cr_amount, code_value, sr_no, posted_to)
	VALUES (@ll_doc,isnull(@dr_amt,0),isnull(@cr_amt,0),@code_vaue,1,@posted_to)

	IF @@ERROR!=0
	BEGIN
		GOTO doerror
	END
	
	INSERT INTO transactions (doc_no, dr_amount, cr_amount, code_value, sr_no, posted_to)
	VALUES (@ll_doc,isnull(@cr_amt,0),isnull(@dr_amt,0),@posted_to,2,@code_value)		
	
	IF @@ERROR!=0
	BEGIN
		GOTO doerror
	END
	END
	
	COMMIT TRANSACTION
	
	Select 0
	
	GOTO doreturn
	
	doerror:
		ROLLBACK TRANSACTION
	doreturn:
		Return 0
		
	Select -100





删除了SHOUTING,添加了代码块 - OriginalGriff [/ edit ]



[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]

推荐答案

Hi friend,

 You are using wrong variable name in second Insert command you are using @code_vaue instead of @code_value.


这篇关于必须声明一个标量变量“@ code_value”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆