Sql 如何在数据集中重复或复制唯一的行?

Sql 如何在数据集中重复或复制唯一的行?,sql,sql-server-2008,tsql,sql-server-2008-r2,Sql,Sql Server 2008,Tsql,Sql Server 2008 R2,这听起来可能有些奇怪,但我们正在使用的物理打印服务将接受SQL调用,并打印返回的行。我们需要相同物理打印的多份副本,因此我们必须拨打相同的电话100多次以上。如果我们能够以某种方式返回一个唯一的行,但在一次调用中返回100次相同的行,那么将节省大量的处理。很遗憾,我们无法传递副本 因此,从PendingPrints p中选择*,其中p.RecId=12345678将返回: ITEM Serial# Description UnusedColumn1 Unus

这听起来可能有些奇怪,但我们正在使用的物理打印服务将接受SQL调用,并打印返回的行。我们需要相同物理打印的多份副本,因此我们必须拨打相同的电话100多次以上。如果我们能够以某种方式返回一个唯一的行,但在一次调用中返回100次相同的行,那么将节省大量的处理。很遗憾,我们无法传递副本

因此,从PendingPrints p中选择*,其中p.RecId=12345678将返回:

ITEM     Serial#        Description       UnusedColumn1   UnusedColumn2
55555    2014021434567  "Fancy Widget"
我们只是打了100多次电话。我需要它以某种方式在一次呼叫中返回:

ITEM     Serial#        Description       UnusedColumn1   UnusedColumn2
55555    2014021434567  "Fancy Widget"
55555    2014021434567  "Fancy Widget"
55555    2014021434567  "Fancy Widget"
55555    2014021434567  "Fancy Widget"
55555    2014021434567  "Fancy Widget"
etc...................................x100

我有一些闲置的列未使用,或者我可以创建一个我一直在想的计数器,这可能会起作用。不过我很好奇,我是否可以用复制之类的方法来重复行。

您可以使用递归CTE或其他方法生成数字,然后使用连接来获得所需的:

with nums as (
      select 1 as n
      union all 
      select n + 1
      from nums
      where n < 100
)
select *
from PendingPrints P join
     nums
     on n.n <= 100
where P.RecId = 12345678 
OPTION (MAXRECURSION 0);

您可以使用递归CTE或其他方法生成数字,然后使用联接来获得所需的:

with nums as (
      select 1 as n
      union all 
      select n + 1
      from nums
      where n < 100
)
select *
from PendingPrints P join
     nums
     on n.n <= 100
where P.RecId = 12345678 
OPTION (MAXRECURSION 0);

您可以使用递归CTE或其他方法生成数字,然后使用联接来获得所需的:

with nums as (
      select 1 as n
      union all 
      select n + 1
      from nums
      where n < 100
)
select *
from PendingPrints P join
     nums
     on n.n <= 100
where P.RecId = 12345678 
OPTION (MAXRECURSION 0);

您可以使用递归CTE或其他方法生成数字,然后使用联接来获得所需的:

with nums as (
      select 1 as n
      union all 
      select n + 1
      from nums
      where n < 100
)
select *
from PendingPrints P join
     nums
     on n.n <= 100
where P.RecId = 12345678 
OPTION (MAXRECURSION 0);
如果需要超过100,则可以在查询结束时添加选项MAXRECURSION 0。如果需要超过100,则可以在查询结束时添加选项MAXRECURSION 0。如果需要超过100,则可以在查询结束时添加选项MAXRECURSION 0。如果需要超过100,则可以在查询结束时添加选项MAXRECURSION 0。