Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Regarding Group

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-02-27 : 12:06:01
Prasad writes "
Hello all,

I need your help to solve the following:

When I give the following sql:

Select datepart(month,crdate) crdate, shortdesc from vwBlogEntries where contributor='testnewsadmin' group by crdate, shortdesc

I get the following output:

crdate shortdesc
===================
5 As a person of the conservative persuasion
1 Growth in Maharashtra, the most favoured destination
1 Kotak Mahindra Investments Ltd has announced
2 THE Government has clarified that


Actually, my requirement is like following.

crdate shortdesc
===================
5 As a person of the conservative persuasion
1 Growth in Maharashtra, the most favoured destination
Kotak Mahindra Investments Ltd has announced
2 THE Government has clarified that

Which means, I want to group based on crdate and supress the repeating values.

Any help on this is most welcome.

Thanks,
Prasad."

jimmy_a
Starting Member

38 Posts

Posted - 2006-02-28 : 00:30:57
I hope u cant do this in a single query .. either u need to use cursor or looping mechanism

"A smile is an inexpensive way to improve your looks"
Go to Top of Page

jimmy_a
Starting Member

38 Posts

Posted - 2006-02-28 : 00:36:36
U can try like this

declare cursor select
open
fetch @empcode
while @@fetchstatus <> 0
if @empcodetmp <> @empcode
begin
set @empcodetmp = empcode
end
else
begin
set @empcodetmp = null
end
insert into temp select @empcodetmp,@empname
fetch next
loop
close cursor
deactive cursor




"A smile is an inexpensive way to improve your looks"
Go to Top of Page

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2006-02-28 : 00:52:38
Hi,
Refer this link..
http://sqljunkies.com/WebLog/amachanic/archive/2004/11/10/5065.aspx?Pending=true
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-28 : 01:21:33
>>Which means, I want to group based on crdate and supress the repeating values.

Where do you want to show the data?
Use Front End application or Reports to Suppress the column if duplicated. Dont try to do this in SQL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jimmy_a
Starting Member

38 Posts

Posted - 2006-02-28 : 01:41:47
Is there any draw back of doing this in backend madhi ???

"A smile is an inexpensive way to improve your looks"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-28 : 01:49:12
It will be ineffecient to do this in SQL. Reports are there for formatting or Displaying the data in the format we want. Suppressing Duplicate values should be done in Reports.

Also read this
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=56067

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

jimmy_a
Starting Member

38 Posts

Posted - 2006-02-28 : 02:26:53
Thanks for ur info madhi...

"A smile is an inexpensive way to improve your looks"
Go to Top of Page
   

- Advertisement -