Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Please help me about sql error !

Author  Topic 

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 01:56:53
use Northwind
create procedure dbo.CalculateFreight
@CustomerID nchar(5) ,
@total money output

as

select @total = sum(Freight) from Orders
where CustomerID = @CustomerID

declare @total money
execute dbo.CalculateFreight @CustomerID='VINET' , @total output
---------- Please help me with this error :
Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@total".
---------- I don't understand why I declared scalar variable but I cann't execute . Whay do i have to do ? Please help me execute it .


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 01:59:04
when you reference one of the parameter with name, you will need to do that for all paramters

execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 03:47:51
I also cann't execute . Hic Hic . Please help me !
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 03:55:24
quote:
Originally posted by hoangit

I also cann't execute . Hic Hic . Please help me !



what is the error messages ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 04:12:40
execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output .
The same as first error .
Cann't declare variable .>>>Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@total".
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 04:13:49
[code]
declare @total money
execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output
select @total
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 04:20:41
when I highlight 2 lines :
declare @total money
execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output
>>>>. It announce successfully
but I highlight one line : execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output
>>>>It announce : Must be scalar variable

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 04:24:38
Thank you so much , I understood . We have to highlight all line when we will run it successfully .
Thank you KHtan . You are so kind and intelligent
Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 04:26:14
what is your yahoo ? Do i want to be your friend , KHtan ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 05:06:52
quote:
Originally posted by hoangit

when I highlight 2 lines :
declare @total money
execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output
>>>>. It announce successfully
but I highlight one line : execute dbo.CalculateFreight @CustomerID='VINET' , @total = @total output
>>>>It announce : Must be scalar variable




Yes. You need to declare the variable to hold the value return from the CalculateFreight procedure. The variable name does not necessary to be the same as the parameter name, for convenience, i just named it the same.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 05:46:46
Yes . I understood . Thanks you . Can you give me your yahoo ?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 06:13:52
Sorry i don't use Yahoo


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

hoangit
Starting Member

8 Posts

Posted - 2012-02-06 : 06:34:27
what is your email ? I think I can ask you something in Java
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-06 : 07:08:10
Sorry, i don't know Java. It is would better and you will get better response if you ask it in a java forum


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -