查询Sql Server - 显示其他查询的空白行

时间:2017-08-07 07:12:28

标签: sql sql-server

您好我的查询有问题:

Select 'N' as Tipo,CONVERT(VARCHAR(10), Noleggio.DataInizioNoleggio, 105) as Data,DATENAME(WEEKDAY, Noleggio.DataInizioNoleggio) as GG,
Trasporto as CodArt,
Trasporto,Matricola,TipoMezzo,
'' as Totale
from Noleggio

enter image description here

除了这些参数,我还有一个名为 - DataTermineNoleggio

我必须在 DATA 中打印 DATAFINENOLLEGGIO 的值,在一个只包含该参数的空行中,我把它应该是结果的图像。我该怎么办?

enter image description here

1 个答案:

答案 0 :(得分:1)

我想你想要实现的目标:

select '',
   CONVERT(VARCHAR(10), Noleggio.DataTermineNoleggio, 105) as Data,
   '','','','','','' 
from Noleggio

但是从我可以理解,你想要一种方法来显示你的行的“开始日期”和“结束日期”...这不会更容易:

Select 'N' as Tipo,
      CONVERT(VARCHAR(10), Noleggio.DataInizioNoleggio, 105) as DataInizio,
      CONVERT(VARCHAR(10), Noleggio.DataTermineNoleggio, 105) as DataTermine,
      DATENAME(WEEKDAY, Noleggio.DataInizioNoleggio) as GG, 
      Trasporto as CodArt,
      Trasporto,
      Matricola,
      TipoMezzo,
      '' as Totale 
from Noleggio