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
 General SQL Server Forums
 New to SQL Server Programming
 update statement raises an error dont know why?

Author  Topic 

sqlontherun101
Starting Member

16 Posts

Posted - 2009-08-27 : 04:20:48
I have written the following script but in the update statement it raised an erorr, cant figureout why?

ALTER PROCEDURE ProcUpdateCustomerCategories

--values for columns
@PCustCatName AS NVARCHAR(100),
@PCustCatDescr as NVARCHAR(MAX),
@PCustCatNo AS INT

AS
BEGIN

declare @InputString NVARCHAR(MAX)
SET @InputString = ''

IF @PCustCatName IS NOT NULL

--ADD THE PCustCatName to the update statement
SELECT @InputString = @InputString + 'catName=' + @PCustCatName;

ELSE
IF @PCustCatDescr IS NOT NULL

-- Add the PCustCatAddress to the update statement
SELECT @InputString = @InputString + ', catDescription=' + @PCustCatDescr;

--this line raises an error
update tblCustomerCategories
SET @InputString where catNo = @PCustCatNo;

END
GO

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-27 : 04:23:08
pdate tblCustomerCategories
SET @InputString where catNo = @PCustCatNo;

assign @inputstring to any of column in the table u mention
so that it is giving error
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2009-08-27 : 04:49:01
Rewrite the update like this


update tblCustomerCategories
column_name = @InputString where catNo = @PCustCatNo;

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-08-27 : 04:57:28
quote:
Originally posted by senthil_nagore

Rewrite the update like this


update tblCustomerCategories
SET
column_name = @InputString where catNo = @PCustCatNo;

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/


Go to Top of Page

sqlontherun101
Starting Member

16 Posts

Posted - 2009-08-27 : 06:24:17
i have to appologize becuase what i have posted is incorrect.

What had in my mind was how do i create (construct) a SQL query update statement, when the table has 3 columns and updates can be entered to the table three ways:
1. update to the Name column
2. update to the description columns
3. updates to Name and Description columm

How do i create a SQL query that will check to which column update is avaiable and only that column(s) should updated by using one update statement in a store procedure.

cheers
Go to Top of Page
   

- Advertisement -