Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Row Number Over Oartiotion help

$
0
0

Hi

I have a script as follows:

select hratency.comp_id
,hratency.tency_seq_no
,hratency.rent_acc_no
,hratency.prty_ref
,hratency.hb_ref
,hratency.bal_freq
,hratency.ethnic_org
,hratency.tency_st_dt
,hratency.tency_end_dt
,hratency.tenure_type
,hratency.res_vacn
--,EndD.prty_ref
,EndD.tency_seq_no
,EndD.Tend
,ROW_NUMBER()OVER(PARTITION BY hratency.prty_ref Order by hratency.prty_ref)AS RowNumber
from hratency
Inner Join QLHRA_TenancyEndPeriod AS EndD
ON hratency.comp_id = EndD.comp_id AND hratency.prty_ref = EndD.prty_ref
where (tency_st_dt > '2014/03/31' AND hratency.tenure_type <> 'OWN' AND hratency.tenure_type <> 'FORMO')

and gives the following output shown in part

i only want to return and rows that have the value of 1 in the RowNumber column and thought the following would work

SELECT * from (select hratency.comp_id
,hratency.tency_seq_no
,hratency.rent_acc_no
,hratency.prty_ref
,hratency.hb_ref
,hratency.bal_freq
,hratency.ethnic_org
,hratency.tency_st_dt
,hratency.tency_end_dt
,hratency.tenure_type
,hratency.res_vacn
--,EndD.prty_ref
,EndD.tency_seq_no
,EndD.Tend
,ROW_NUMBER()OVER(PARTITION BY hratency.prty_ref Order by hratency.prty_ref)AS RowNumber
from hratency
Inner Join QLHRA_TenancyEndPeriod AS EndD
ON hratency.comp_id = EndD.comp_id AND hratency.prty_ref = EndD.prty_ref
where (tency_st_dt > '2014/03/31' AND hratency.tenure_type <> 'OWN' AND hratency.tenure_type <> 'FORMO'))
where RowNumber=1
but i get the following error message

Msg 156, Level 15, State 1, Line 20
Incorrect syntax near the keyword 'where'

Having looked at this for ages i think i am blind now to the solution. Can anyone assist please

Thanks

John


Viewing all articles
Browse latest Browse all 10045

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>