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.
| 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 ASBEGIN 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;ENDGO |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-08-27 : 04:23:08
|
| pdate tblCustomerCategoriesSET @InputString where catNo = @PCustCatNo;assign @inputstring to any of column in the table u mentionso that it is giving error |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-08-27 : 04:49:01
|
| Rewrite the update like thisupdate tblCustomerCategoriescolumn_name = @InputString where catNo = @PCustCatNo;Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
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 thisupdate tblCustomerCategoriesSET column_name = @InputString where catNo = @PCustCatNo;Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
|
 |
|
|
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 column2. update to the description columns3. updates to Name and Description colummHow 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 |
 |
|
|
|
|
|