作业帮 > 综合 > 作业

能否在from 之后加 case when 语句?

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/28 12:56:48
能否在from 之后加 case when 语句?
能否在from 之后加 case when 语句?
实现如下需求如不美观table1的col1字段 值为 1,年夜test1表中取数据如不美观table1的col1字段 值为 2,年夜test2表中取数据create table test1( col int);insert test1 (col) values(10);create table test2( col int);insert test2 (col) values(20);create table table1( col1 int, col2 int, col3 int, col int);insert table1 (col1) values(1);--如不美观table1的col1字段 值为 1,年夜test1表中取数据--如不美观table1的col1字段 值为 2,年夜test2表中取数据declare @tempid intselect @tempid = col1 from table1-- 下面代码无法使用-- select * from (case when @tempid = 1 then test1 else test2 end)