|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Stored Procedure for update : update selected fields depending on indicatorsis it possible to create a stored procedure with parameters, so that you can say for example : update table if @indicator1 = 1 then set field1 = @field1 if @indicator2 = 1 then set field2 = @field2 ..... where keyfield = @keyfield ? thank you, kind regards , sven Something like ...
CREATE PROCEDURE TestProc ( @indicator1 int ,@indicator2 int ,@field1 varchar(50) ,@field2 varchar(50) ,@keyfield int ) AS IF @indicator1 = 1 THEN UPDATE MyTable SET Field1 = @field1 WHERE keyfield = @keyfield IF @indicator2 = 1 THEN UPDATE MyTable SET Field1 = @field2 WHERE keyfield = @keyfield -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA *************************** Think Outside the Box! *************************** "sven.m***@gmail.com" wrote: > Hello, > > > is it possible to create a stored procedure with parameters, > so that you can say for example : > > update table > > if @indicator1 = 1 then set field1 = @field1 > if @indicator2 = 1 then set field2 = @field2 > ..... > > where keyfield = @keyfield ? > > > thank you, > kind regards , > > sven > > How about something like this:
UPDATE MakeBelieveTable SET Column1 = CASE WHEN @indicator1 = 1 THEN @Value1 ELSE Column1 END, SET Column2 = CASE WHEN @indicator2 = 1 THEN @Value2 ELSE Column2 END, ...... The idea is to set the column to either the passed in value, or the column's current value, depending on the indicator value. Note, since you did not provide any DDL, this is completely untested, but you should be able to modify it to make it work for you. IHTH Jeremy <sven.m***@gmail.com> wrote in message Show quote news:1120223798.864151.260550@g43g2000cwa.googlegroups.com... > Hello, > > > is it possible to create a stored procedure with parameters, > so that you can say for example : > > update table > > if @indicator1 = 1 then set field1 = @field1 > if @indicator2 = 1 then set field2 = @field2 > .... > > where keyfield = @keyfield ? > > > thank you, > kind regards , > > sven >
Other interesting topics
|
|||||||||||||||||||||||