Home All Groups Group Topic Archive Search About

Correct syntax for an update stored procedure

Author
24 Nov 2005 3:03 PM
martinharvey
This is probably a very simple question but i would appreciate some help with
the correct syntax for and update stored procedure

I  have created  a user form that allows the user to update the name and
address fields in a datatable called  customers based on the input value
customer ID =  ( datatable/Customers)customerID

I have got this far and then got lost:

Create SP_UpdateCustomer
(@customerID, @name, @address)

As

Update customers ( name, address)

Where customerID =  @customerID

GO

Could anyone tell me what the correct sntax should be.

many thanks

Martin


Author
24 Nov 2005 3:18 PM
Mark Rae
"martinharvey" <u14945@uwe> wrote in message news:57d57cab571aa@uwe...

> This is probably a very simple question

It is, and has very little to do with ASP.NET -
microsoft.public.sqlserver.programming would have been the correct newsgroup
to post this...

> but i would appreciate some help with
> the correct syntax for and update stored procedure

A quick search in Books OnLine, or even Google, would have answered this for
you straightaway.

Show quoteHide quote
> I  have created  a user form that allows the user to update the name and
> address fields in a datatable called  customers based on the input value
> customer ID =  ( datatable/Customers)customerID
>
> I have got this far and then got lost:
>
> Create SP_UpdateCustomer
> (@customerID, @name, @address)
>
> As
>
> Update customers ( name, address)
>
> Where customerID =  @customerID
>
> GO
>
> Could anyone tell me what the correct sntax should be.

On the assumption that 'customerID' is an int, and that 'name' and 'address'
are varchar(50), the syntax is as follows:

CREATE uspUpdateCustomer
    @customerID int,
    @name varchar(50),
    @address varchar(50)
AS
UPDATE
    customers
SET
    [name] = @name,
    address = @address
WHERE
    customerID = @customerID


Also:

1) avoid naming stored procedures SP_xxxxx
http://www.devx.com/tips/Tip/14432

2) avoid using SQL keywords e.g. 'name' as table names or field names
Are all your drivers up to date? click for free checkup

Author
24 Nov 2005 3:19 PM
hn
Create Procedure SP_UpdateCustomer
(@customerID Int,
@name NVarchar(200),
@address NVarchar(200)
)

As

update customers set name = @name,
address = @address
where customerID  =  @customerID    

GO

Show quoteHide quote
"martinharvey" wrote:

> This is probably a very simple question but i would appreciate some help with
> the correct syntax for and update stored procedure
>
> I  have created  a user form that allows the user to update the name and
> address fields in a datatable called  customers based on the input value
> customer ID =  ( datatable/Customers)customerID
>
> I have got this far and then got lost:
>
> Create SP_UpdateCustomer
> (@customerID, @name, @address)
>
> As
>
> Update customers ( name, address)
>
> Where customerID =  @customerID

> GO
>
> Could anyone tell me what the correct sntax should be.
>
> many thanks
>
> Martin
>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200511/1
>
Author
24 Nov 2005 3:21 PM
Bill Manring
Martin,

The correct syntax for a simple UPDATE command would be:

Update customers Set name = @name, address = @address
Where customerID =  @customerID

--
Hope this helps,

Bill Manring
Show quoteHide quote
"martinharvey" wrote:

> This is probably a very simple question but i would appreciate some help with
> the correct syntax for and update stored procedure
>
> I  have created  a user form that allows the user to update the name and
> address fields in a datatable called  customers based on the input value
> customer ID =  ( datatable/Customers)customerID
>
> I have got this far and then got lost:
>
> Create SP_UpdateCustomer
> (@customerID, @name, @address)
>
> As
>
> Update customers ( name, address)
>
> Where customerID =  @customerID

> GO
>
> Could anyone tell me what the correct sntax should be.
>
> many thanks
>
> Martin
>
> --
> Message posted via DotNetMonster.com
> http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net/200511/1
>

Bookmark and Share