问题
I am using following Query to Display Records from SQL SERVER
select * from orders
Currently this query shows all 100 records in database, what i need is instead of 100 it should show 200 records ( so alternate blank records is fine ) It is possible can it be done ?
回答1:
-- 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
Result:
orderid qty
----------- -----------
1 10
NULL NULL
2 20
NULL NULL
3 30
NULL NULL
来源:https://stackoverflow.com/questions/7586122/sql-query-add-an-alternate-blank-records