简体   繁体   中英

How to set and return a column Value in SQL Stored Procedure within If else statement

In reference to my Previous Question I am not sure how can I set and then return a column data value with out saving it to table.

if @datafield = 1
set ColumnA.table2=1
else if @datafield = 2 AND @datafield2 = 3
set ColumnA.table2= 0
else
return (SELECT ColumnA.table2 FROM table1 INNER JOIN table2 on table1.id and table2.id Where @datafield3 = 0)

I am not sure how to return after setting values, I did tried begin and end , not working tho

simplest thing you can do to return value

Declare @returnvalue int

if @datafield = 1
   set @returnvalue=1
else if @datafield = 2 AND @datafield2 = 3
set @returnvalue= 0
else
     SELECT @returnvalue=ColumnA.table2 FROM table1
        INNER JOIN table2 on table1.id and table2.id 
        Where @datafield3 = 0

 select @returnvalue as ColumnA
 return @returnvalue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM