Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Stored Procedure for updating dynamic columns in a table

$
0
0

I have a table with a lot of columns around 30ish

Now I want to create a stored procedure that will update a specific column to a new value.

I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.

here's my Stored Procedure

USE [db] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[usp_UpdateData] @itemID int, @ColumnName varchar(50), @newValue nvarchar(50) AS BEGIN Update dbo.ProjectAllocation Set @ColumnName = @newValue Where itemID = @itemID

END

When I pass the following

@ColumnName: UserName

@newValue: NewUserName

@itemID: 1

it doesnt update row with itemID = 1.

How can I do this?


----------------------- Sharepoint Newbie



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>