Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedures - Doesn't exept consts 2

Status
Not open for further replies.

JOBARAM

Programmer
May 25, 2002
52
IL
Hi,
Stored procedures are very new to me and I guess my Q stupid, but I'll go a head any way.
Why doesn't it works?
Alter Procedure UpdateProc @Clientx char(10), @ClientNum int AS Update Product Set @Clientx= @ClientNum
All I want to do is sending 2 parameters to the procedure (Filed name and Value) and to update. It only let me do that if the field name is written as it is in the procedure.
Thanks
Yossi
 
Somebody with more experience than me may have a better answer, but I don't think you can pass the field name directly. However, something like this should work:

if @clientx = 'fieldname1'
update Product Set fieldname1 = @ClientNum
else
if @clientx = 'fieldname2'
update Product Set fieldname2 = @ClientNum

Obviously, if you have a lot of fields to deal with, a CASE statement would be a better choice than a series of IF statements.
 
SQL doesn't allow the use of variables for column names. I like WoodLark's solution when you have a few options.
See thread183-299640 for some dynamic SQL methods. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top