我在这里做了一张简单的小table:
declare @live bit = 1
declare @temp table(id int, title varchar(30))
insert into @temp (id, title)
select 1, 'myTitle1'
union select 2, 'myTitle2'
union select 3, 'myTitle3'
select * from @temp
输出:
id title
-------------
1 myTitle1
2 myTitle2
3 myTitle3
现在我希望title属性依赖于@live
我将用伪代码显示它:
declare @live bit = 1
declare @temp table(id int, title varchar(30))
insert into @temp (id, title)
select 1, IF (@live == 1) THEN 'myTitle1_live' ELSE 'myTitle1'
union select 2, IF (@live == 1) THEN 'myTitle2_live' ELSE 'myTitle2'
union select 3, IF (@live == 1) THEN 'myTitle3_live' ELSE 'myTitle3'
select * from @temp
这在sql语法中是什么样子的?
1条答案
按热度按时间lrpiutwd1#
我想你只需要一个条件表达式:
如果数据已经在表中,那么您将使用
update
: