1

I am running this query in SQL:

select
--CLAIM_ID,
--sum (paid_amount),
(ROW_NUMBER() OVER (partition by claim_id order BY claim_id) as asdf)
from [FRAUD].[dbo].[MU_GAPA_ADS_CLAIM_ANALYSIS_ALLACCOUNTS]
where (ALTGRP like '48000%') and (svcDAT between '10/01/2016' and '10/01/2016') 
Group By claim_id

However, I heep getting the following error:

Msg 156, Level 15, State 1, Line 4 Incorrect syntax near the keyword 'as'.

Can someone please help me understand what is going on and how I can solve it?

Thank you.

3
  • 4
    Seems you use way to many parentheses. Commented Jul 3, 2018 at 13:06
  • And be careful with those date strings. You should use the ANSI standard YYYYMMDD. Commented Jul 3, 2018 at 13:07
  • @HoneyBadger what would be the correct syntax, using the appropriate parentheses etc? Commented Jul 3, 2018 at 13:08

1 Answer 1

2

The problem isn't row_number(). The problem is the parentheses around the column alias:

ROW_NUMBER() OVER (partition by claim_id order BY claim_id) as asdf

You should also fix the date constants:

select CLAIM_ID, sum(paid_amount),
       row_number() over (partition by claim_id order by claim_id) as asdf)
from [FRAUD].[dbo].[MU_GAPA_ADS_CLAIM_ANALYSIS_ALLACCOUNTS]
where ALTGRP like '48000%' and
     svcDAT between '2016-10-01' and '2016-10-01'
Group By claim_id;

All that said, the row_number() is always going to return "1" for this query, so you might as well leave it out.

Sign up to request clarification or add additional context in comments.

3 Comments

Is this because I am grouping by Claim_ID only? I will add some other variables to group by which will result in Claim_ID repetitions. Essentially, I would like to get a count of the number of times each claim ID shows up
sounds like you just need COUNT(claim_id ) AS asdf
@Magretto . . . You should ask another question, with appropriate data and a description of what you want. This seems to answer this question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.