473,513 Members | 2,800 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Stored procedure syntax problem

I would be very grateful if someone could help me with a stored procedure
syntax problem

I want to insert the value "OrderTotal" into databasetable("Newtable") column
"OrderTotal"
(money (8)). The value can be returned from the page (Dim amount As Decimal =
ShoppingCart.GetTotal() totalAmountLabel.Text = String.Format("{0:c}",amount)
or returned by the function "ShoppingCart.GetTotal".

This is the syntax i have tried, but I get the error message "Invalid column
name OrderTotal"

CREATE PROCEDURE SP_NewOrder
(@CartID char (36),@CustomerID Varchar (50),@OrderTotal decimal(8))

AS

INSERT INTO NewTable (FirstName,ProductID,OrderTotal)

SELECT Customer.FirstName,Products.ProductID,Ordertotal

From Customer,Products Join ShoppingCart ON Products.ProductID =ShoppingCart.
ProductID
WHERE Customer.CustomerID=@CustomerID AND ShoppingCart.CartID = @CartID
GO

Can anyone tell me where i am going wrong

many thanks

martin

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200512/1
Dec 2 '05 #1
2 1449
Hi,

Simple mistake but surprisingly easy to over look. When ever you use
variables in Transac SQL you need to prefix it with the '@' symbol so the
select statement will become:

Select Customer.FirstName, Products.ProductID, @OrderTotal

It is not however, case sensitive it is just the fact it's missing the @.

Another problem you will be having once that is fixed is the declaration of
the decimal. It differs from the other type declarations. The other tryes
require you to set the size of the variable. For example @CartID char(36)
gives you a char with 36 bytes.

The decimal in your database takes up 9 bytes (or whatever you set it to)
however, when you declare the variable you need to specify the persition
(number of intergers) and the scale (number of decimal places) so:

Create Procedure SP_NewOrder (@CartID char(36), @CustomerID varchar(50),
@OrderTotal decimal(18,4) )

AS ...

Would give you a decimal with 4 decimal places.

Hope this helps

- Mike

---------------------------------------------------------------------------------
<a href="http://www.cogitar.net"> Cogitar Software. (http://www.cogitar.net)
</a>
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://shop-dominion.com (senery landscape pictur gallery)
---------------------------------------------------------------------------------

"martinharvey via DotNetMonster.com" <u14945@uwe> wrote in message
news:583d793a0b56e@uwe...
I would be very grateful if someone could help me with a stored procedure
syntax problem

I want to insert the value "OrderTotal" into databasetable("Newtable")
column
"OrderTotal"
(money (8)). The value can be returned from the page (Dim amount As
Decimal =
ShoppingCart.GetTotal() totalAmountLabel.Text =
String.Format("{0:c}",amount)
or returned by the function "ShoppingCart.GetTotal".

This is the syntax i have tried, but I get the error message "Invalid
column
name OrderTotal"

CREATE PROCEDURE SP_NewOrder
(@CartID char (36),@CustomerID Varchar (50),@OrderTotal decimal(8))

AS

INSERT INTO NewTable (FirstName,ProductID,OrderTotal)

SELECT Customer.FirstName,Products.ProductID,Ordertotal

From Customer,Products Join ShoppingCart ON Products.ProductID
=ShoppingCart.
ProductID
WHERE Customer.CustomerID=@CustomerID AND ShoppingCart.CartID = @CartID
GO

Can anyone tell me where i am going wrong

many thanks

martin

--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200512/1

Dec 3 '05 #2
wrote:
Hi,

Simple mistake but surprisingly easy to over look. When ever you use
variables in Transac SQL you need to prefix it with the '@' symbol so the
select statement will become:

Select Customer.FirstName, Products.ProductID, @OrderTotal

It is not however, case sensitive it is just the fact it's missing the @.

Another problem you will be having once that is fixed is the declaration of
the decimal. It differs from the other type declarations. The other tryes
require you to set the size of the variable. For example @CartID char(36)
gives you a char with 36 bytes.

The decimal in your database takes up 9 bytes (or whatever you set it to)
however, when you declare the variable you need to specify the persition
(number of intergers) and the scale (number of decimal places) so:

Create Procedure SP_NewOrder (@CartID char(36), @CustomerID varchar(50),
@OrderTotal decimal(18,4) )

AS ...

Would give you a decimal with 4 decimal places.

Hope this helps

- Mike

---------------------------------------------------------------------------------
<a href="http://www.cogitar.net"> Cogitar Software. (http://www.cogitar.net)
</a>
http://www.web-dominion.co.uk Web-Dominion. (Web Design and hosting )
http://shop-dominion.com (senery landscape pictur gallery)
---------------------------------------------------------------------------------
I would be very grateful if someone could help me with a stored procedure
syntax problem

[quoted text clipped - 32 lines]

many thanks for your he;p with this mike

Martin martin


--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/For...p-net/200512/1
Dec 4 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2837
by: Toonman | last post by:
I'm trying to use a couple of variables in a stored procedure. Things work fine when I hard code the data into the variables and also work fine when I use the variable in the WHERE clause and hard code data for the other variable. So, I think I have a syntax problem when trying to use "FrontPage.@FrontpageProduct" as seen in my example code...
4
3303
by: Jarrod Morrison | last post by:
Hi All Im using a stored procedure on my sql server and am unsure of the syntax that i should use in it. Im pretty sure that there is a way to do what i want, but as yet i havent been able to find much info on it. Basically the procedure takes the machinename and username supplied and searches a table or two for some matches and this part...
4
13459
by: marc | last post by:
I've been developing a stored procedure that uses a user defined function in the query portion of the procedure. However, since the end product needs to allow for dynamic table names, the UDF will not work. I've been trying to get this to work with converting the UDF to a procedure, but I'm having no luck. Here is the background on what I'm...
12
10365
by: Bill Nguyen | last post by:
What's the VB syntax to run the CR report using the following SP? I use CrystalreportViewer and ReportDocument. Thanks Bill Here's the SP in SQLserver 2K: CREATE proc mysp_ReportSubmission @salesdate as varchar(20),
9
2446
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug through the application in Visual Studio .NET 2003 the application an exception when it executes the query.
7
5834
by: eholz1 | last post by:
Hello PHP group, Could someone help me out? I have PHP 5.2, Apache 2.0, and MySQL 5.0 running on Linux (Redhat Fedora Core 6). All that works fine. I would like to be able to "call" a stored procedure from a PHP program, and run a stored procedure. I have yet to figure out the proper way to do this. My stored procedures work fine...
5
3614
by: Dennis | last post by:
Hi I'm trying to alter my stored procedure to take a parameter for the Database Name, but as usual the syntax is killing me. Thanks for any help Dennis '--------------------------------------------------------------------------­-------------------------------- Before - This Works without a paramater...
20
6280
by: billmaclean1 | last post by:
I need to write a stored procedure that selects from a table and returns the result set. I don't always know the TableSchema that I need to use when qualifying the table at run-time Example: The correct table could either be dbo.MyTable or zzz.MyTable. I want the user to enter the name of the schema as a parameter of the procedure at...
6
7264
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable (confirmation) declared in page. Dim RsSp , SQLSp Set RsSp = Server.CreateObject("ADODB.Recordset") SQLSp = "Declare @confirm varchar(1)"...
2
2807
by: priyamtheone | last post by:
I'm trying to create a stored procedure in MSSQL Server 2005 that'll perform the following jobs: 1) Create a login. 2) Create an user in TestDB database for the login created in step 1. 3) Assign the role 'db_generaluser' to the user created in step 2. The login name and password for the login to be created will be supplied from externally...
0
7273
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7181
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7570
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7131
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7545
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3256
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1615
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
821
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
480
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.