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
 General SQL Server Forums
 New to SQL Server Programming
 how to write a query for this

Author  Topic 

ramya888
Starting Member

11 Posts

Posted - 2013-07-23 : 03:00:46
i am getting a output like this,

lname cperson desig cno extnno faxno mobilno location
ZZZZZ arun exe 2 456 787 98989 mumbai
zzzzz ram MNG 3 454 909 89878 mumbai
zzzzz kk Smng 4 343 888 78987 mumbai

but i want like this
lname cperson desig cno extnno faxno mobilno location
ZZZZZ arun exe 2 456 787 98989 mumbai
ram MNG 3 454 909 89878
kk Smng 4 343 888 78987

here lname and location there is a repetation,so i want to show only one lname records and one location records,because it has same name which is repeting in the records,is there any way to do like this

Ramy

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-07-23 : 03:59:35
This property is called suppress duplicates or hide duplicates and is available on most of the front end reporting tools. You can find this property within textbox properties in SSRS

Doing this in SQL is ugly as its a presentation issue.
However if you really have no other choice use the below


SELECT CASE WHEN Seq=1 THEN lname ELSE '' END AS lname,
cperson, desig,cno, extnno, faxno, mobilno, location
FROM
(
SELECT ROW_NUMBER() OVER (PARTITION BY lnamefield ORDER BY cno) AS RN,...
... Rest of your query
)t


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2013-07-23 : 07:57:28
quote:
Originally posted by ramya888

i am getting a output like this,

lname cperson desig cno extnno faxno mobilno location
ZZZZZ arun exe 2 456 787 98989 mumbai
zzzzz ram MNG 3 454 909 89878 mumbai
zzzzz kk Smng 4 343 888 78987 mumbai

but i want like this
lname cperson desig cno extnno faxno mobilno location
ZZZZZ arun exe 2 456 787 98989 mumbai
ram MNG 3 454 909 89878
kk Smng 4 343 888 78987

here lname and location there is a repetation,so i want to show only one lname records and one location records,because it has same name which is repeting in the records,is there any way to do like this

Ramy


Where do you want to show data? If you use reporting tool, use Suppress if duplicate option

Madhivanan

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

- Advertisement -