怎么用sql写替换

来源:百度知道 编辑:UC知道 时间:2024/06/08 07:14:41
我要查询一张表,绑定到GridView里显示,表里有字段a,b是bit型
我想当a为1时,我在GridView里的一个label显示“精华帖”
当b为1时,在GridView里的另一个label显示“屏蔽贴”
用的是存储过程,我定义了两个varchar的字段ber,der,为null,和a,b两个字段一块查询
如:DECLARE @ber nvarchar(30),
@der nvarchar(30)
select a,b,@ber as ber,@der as der from tablename where x='??'
我想当a=1的时候,ber='精华帖'.当b=1的时候,der=‘屏蔽贴’
所以写了两个语句
DECLARE @ber nvarchar(30),
@der nvarchar(30)
update
(select a,b,@ber as ber,@der as der from tablename where x='??'
)as t1
set ber='精华帖'
where a=1

另外一个类似
运行的时候总提示“update(”附近错误 和 “)as t1”附近错误
大概是什么问题,最好能写写过程,谢谢

update 语句不能更新临时表的吧?

对于你描述的这个精华帖和屏蔽贴的问题
我做的时候是在GridView的RowDataBound事件里
判断当前数据行中a和b的值,然后做相应的输出
希望能对你有帮助~

可能是(select a,b,@ber as ber,@der as der from tablename where x='??'
)语句有不对的地方