Sql 当查询返回时没有数据时输入伪行

Sql 当查询返回时没有数据时输入伪行,sql,sql-server,sql-server-2008,insert,Sql,Sql Server,Sql Server 2008,Insert,我运行一个用于excel的查询。数据通过一个程序每周更新一次。有时,过程返回时没有数据。在这些情况下,我想添加一个带有日期的虚拟行,这样excel的用户就可以看到没有该日期的数据 我有一个名为TAG的专栏。这是标签1-4。如果标记3返回时没有数据,我想插入一行 我只有一张tmp桌。如果它不包含标记3的数据,我想添加一个只有日期但没有数据的伪行 CREATE procedure [dbo].[pr_quality_weekly] as begin insert into #tmp(date

我运行一个用于excel的查询。数据通过一个程序每周更新一次。有时,过程返回时没有数据。在这些情况下,我想添加一个带有日期的虚拟行,这样excel的用户就可以看到没有该日期的数据

我有一个名为TAG的专栏。这是标签1-4。如果标记3返回时没有数据,我想插入一行


我只有一张tmp桌。如果它不包含标记3的数据,我想添加一个只有日期但没有数据的伪行

CREATE procedure [dbo].[pr_quality_weekly]
as
begin   

insert into #tmp(date_run,country,tag,company,campaign,seller,orderdate,reg_date,enddate,cust_desc1,cust_desc2,phone_1,phone_2,delivery,reason,date_of_birth,product)

Select  * FROM prod_no
where date between datfrom and dateto

insert into #tmp(date_run,country,tag,company,campaign,seller,orderdate,reg_date,enddate,cust_desc1,cust_desc2,phone_1,phone_2,delivery,reason,date_of_birth,product)

Select  * FROM prod_se
where date between datfrom and dateto

Insert into prod_weekly (date_run,country,tag,company,campaign,seller,orderdate,reg_date,enddate,cust_desc1,cust_desc2,phone_1,phone_2,delivery,reason,date_of_birth,product)
(Select date_run,country,tag,company,campaign,seller,orderdate,reg_date,enddate,cust_desc1,cust_desc2,phone_1,phone_2,delivery,reason,date_of_birth,product 
from #tmp)

END

虽然我不知道您的代码在做什么,但创建该行可能很简单,但如果prod weekly表中有
notnull
列,则必须提供空字符串作为填充符

Select date_run,country,days.tag,company,campaign
     , seller,orderdate,reg_date,enddate
     , cust_desc1,cust_desc2
     , phone_1,phone_2,delivery,reason,date_of_birth,product 
from (values (1),(2),(3),(4),(5)) days(tag)
left join #tmp on days.tag=#temp.tag

我只有一张tmp桌。如果它不包含标记3的数据,我想添加一个只有日期但没有数据的虚拟行。您需要在这里为我们实际添加一些内容-向我们展示您编写的代码。不要用语言向我们描述它。。。给我们看看代码。(也不要把它放在评论里,格式太糟糕了——编辑你的问题并把它添加到那里。