Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 2005 SQL查询添加备用空白记录_Sql Server 2005 - Fatal编程技术网

Sql server 2005 SQL查询添加备用空白记录

Sql server 2005 SQL查询添加备用空白记录,sql-server-2005,Sql Server 2005,我使用以下查询来显示来自SQL SERVER的记录 select * from orders 目前,这个查询显示数据库中的所有100条记录,我需要的是,它应该显示200条记录,而不是100条记录(所以备用空白记录是可以的),这是可能的吗 -- sample table declare @Order table ( orderid int, qty int ) -- add some data insert into @Order select 1, 10 union all sel

我使用以下查询来显示来自SQL SERVER的记录

select * from orders
目前,这个查询显示数据库中的所有100条记录,我需要的是,它应该显示200条记录,而不是100条记录(所以备用空白记录是可以的),这是可能的吗

-- sample table
declare @Order table
( 
  orderid int,
  qty int
)

-- add some data
insert into @Order
select 1, 10 union all
select 2, 20 union all
select 3, 30

-- cross join the query against two rows       
select case D.N when 1 then O.orderid end as orderid,
       case D.N when 1 then O.qty end as qty
from @Order as O
  cross join (select 1 union all select 2) as D(N)
order by O.orderid, D.N  
结果:

orderid     qty
----------- -----------
1           10
NULL        NULL
2           20
NULL        NULL
3           30
NULL        NULL
结果:

orderid     qty
----------- -----------
1           10
NULL        NULL
2           20
NULL        NULL
3           30
NULL        NULL

这最好在表示层完成。出于兴趣,为什么要这样做?这是否可能是对数据呈现方式的要求?表示逻辑实际上应该与数据上的CRUD(创建、检索、更新、删除)操作分开。这最好在表示层完成。出于兴趣,为什么要这样做?这是否可能是对数据呈现方式的要求?表示逻辑实际上应该与数据上的CRUD(创建、检索、更新、删除)操作分开。。