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 |
|
anabelle
Starting Member
19 Posts |
Posted - 2009-04-15 : 03:59:20
|
| I got a scenario here wherein i have to query a records which wud not duplicates:i have the ff query statement select (*)from tablesamplegroup by Pro1,pro2,namehaving by (count(pro1)>1) it display the followingPro1 Pro2 Name1 T1 Emma1 T1 Lourdes1 T1 Rems1 T1 Myra1 T1 Elma2 T2 Emmanuel2 T2 Erns3 T3 Hana4 T4 Glenwhat i would like to happen is to display only the ff:Pro1 Pro2 Name1 T1 Emma2 T2 Emmanuel3 T3 Hana4 T4 GlenHow wud i renovate my sql statement so that it will only display and query single record with single name..? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-15 : 04:49:19
|
SELECT Pro1, Pro2, NameFROM (SELECT Pro1, Pro2, Name, ROW_NUMBER() OVER (PARTITION BY Pro1 ORDER BY Name) AS recIDFROM [TableSample]) AS dWHERE recID = 1 E 12°55'05.63"N 56°04'39.26" |
 |
|
|
anabelle
Starting Member
19 Posts |
Posted - 2009-04-15 : 05:38:27
|
| Peso, i am having that syntax error that is something on ur row_number()over (OVER (PARTITION BY Pro1 ORDER BY Name) AS recIDMsg 102, Level 15, State 1, Line 10Incorrect syntax near '('. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-04-15 : 05:41:58
|
Change your compatibility level for the current database to 90 or higher. E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-04-15 : 07:01:06
|
| try like this too declare @tbl as table(Pro1 INT, Pro2 VARCHAR(4),[Name] varchar(40))insert into @tbl select1, 'T1', 'Emma' union all select1, 'T1', 'Lourdes' union all select1, 'T1', 'Rems' union all select1, 'T1', 'Myra' union all select1, 'T1', 'Elma' union all select2, 'T2', 'Emmanuel' union all select2, 'T2', 'Erns' union all select3, 'T3', 'Hana' union all select4, 'T4', 'Glen' select identity(int,1,1) as rid, * into #temp from @tblselect pro1,pro2,[name] from (select *,(select count(*) from #temp where rid <= t.rid and Pro2 = t.Pro2) as cntfrom #temp t )s where s.cnt = 1drop table #temp |
 |
|
|
|
|
|
|
|