I got a simple query which return a results from an OrderLine table. Is there a way to visually separate the query results to make it easier to read, like in the image shown here?
x
SELECT [OrderNo], [LineNo] FROM [OrderLine]Results:
Advertisement
Answer
drop table if exists #OrderLine;select object_id as OrderNo, abs(checksum(newid())) as [LineNo]into #OrderLinefrom sys.columns;-- results to text (ctrl+T)?select OrderNo, [LineNo], case when lead(OrderNo, 1) over(partition by OrderNo order by OrderNo) = OrderNo then '' else replicate('-', 11) + char(10) endfrom #OrderLine;--inject NULLselect case when [LineNo] is null and flag=2 then null else TheOrderNo end as OrderNo, [LineNo]from( select OrderNo AS TheOrderNo, [LineNo], 1 as flag from #OrderLine union all select distinct OrderNo, NULL, 2 from #OrderLine) as srcorder by TheOrderNo, flag;