Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Break On" format of columns 1

Status
Not open for further replies.

squirleegirl

Programmer
Jun 24, 2003
59
US
Hi ~ I have a query that I want to format the columns.

Instead of this:
1 Data1 Date
2 Data1 Date
3 Data2 Date
4 Data2 Date

I would like this:
Data1 1 Date
2 Date
Data2 3 Date
4 Date

The Oracle statement is 'break on [columnname];' But, unfortunately I am not using Oracle ~ I am using MS Sql Server.

Does anyone know what the command for SQL Server is or another method that will format the output like I need it?

Thanks,
Squirleegirl
 
What reporting tool are you using?

If possible grouping the data should be carried out by the reporting tool.

 
The report should do the formatting. SQL server does not as far as I know support what you are trying to do.


Questions about posting. See faq183-874
 
The report is doing the formatting. However, frequently I do queries and such directly from Enterprise Manager (stuff for me, not for distro) and I was just wondering what the command was. I don't need it for the report itself ~ more for my knowledge.
 
As far as i'm aware there is not a specific command.

The result could be acheived by replacing a value with NULL if it was repeated but this would involve a loop I think.
 
This would be easiest do with a report than with SQL and as jonwold said logic has to be added to do what u r looking for.
Try this sample code.

Code:
create Table #t(i int,c varchar(25),d varchar(25))

insert into #t
Select 1,    'Data1',     'Date'
UNION
Select 2,    'Data1',     'Date'
UNION
Select 3,    'Data2',     'Date'
UNION
Select 4,    'Data2',     'Date'


select 
Case when (Select count(*) from #t t1 Where t1.c=t.c and t1.d=t.d and t1.i<=t.i)=1 then c else '' End FLDName 
,i,d
from #t t

Sunil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top