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.
Author |
Topic |
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2013-12-17 : 10:23:43
|
Hi I am working in sqlserver 2008 r2. Below is my table structureTable Name : DetailsClient, company, division, activegoogle, abc, finance, 1google, abc, management, 1google, def, HR,1my query is select Client, company, division, active from details where client = 'google'My desired output should be :google, abc, finance, 1 abc, management, 1 def, HR,1How to avoid the client name repeating in every rows.if possible please show me some sample query to achieve this,Thanks in advance. |
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2013-12-17 : 10:49:11
|
This is a display issue. What are you using to display this information? Is it some kind of report writer or application? If so you should use that to control this conditional rendering of Client.If you need to do this in sql you would need something like this:select case when rn = 1 then Client else null end as Client ,company , division , activefrom ( select Client , company , division , active , row_number() over (partition by client order by company, division, active) as rn from details where client = 'google' ) d Be One with the OptimizerTG |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2013-12-17 : 11:14:58
|
Awesome TG!! This is what i expected and i learnt today from you that how to do this using rownumber.Thanks a lot |
|
|
|
|
|
|
|