Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:55:59+00:00 2026-06-14T06:55:59+00:00

This one will be quick. I can’t get exactly what I want out of

  • 0

This one will be quick. I can’t get exactly what I want out of the row_number() function. What I get:
enter image description here

I need the row_number() to increment only on different patids that have different dailyDosage. So rows 4-9 on the screen cap should all be 1. Row 13 should be 1 (because it’s a new patid) and row 14 should be 2 (because of the change in daily dosage. What I get:

select distinct 
     ROW_NUMBER() over(partition by rx.patid,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int) 
     order by rx.patid,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int))
     ,rx.patid
    ,rx.drugName
    ,rx.strength
    ,rx.quantity
    ,rx.daysSup
    ,rx.fillDate
    ,quantity/daysSup*cast(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') as int) as dailyDosage
    from rx 
    inner join (select distinct m.patid, m.sex, m.injurylevel from members as m) as m on m.PATID=rx.patid
    where ISNUMERIC(REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m',''))=1 
    and REPLACE(LEFT(strength,PATINDEX('%[^0-9]%',strength)),'m','') not like '%.%' 
    and drugname in ('baclofen')
    and daysSup !=0 and quantity !=0
    and daysSup > 1
    order by rx.patid

SQL Server 2008 R2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:56:01+00:00Added an answer on June 14, 2026 at 6:56 am

    I think you are trying to rank the daily dosages. Try using dense_rank rather than row_nubmer.

    Row_number enumerates the rows. Ranks keep the same values together. Dense_rank does the enumeration, assigning the first group 1’s, the next group 2’s, and so on. Rank leaves gaps in the numbering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help with one ajax function This is raw page setup. Page will
Hoping this will be a quick/easy one, but I can't seem to find the
This will hopefully be a simple one: I have a div I want to
Example: /** * This function will determine whether or not one string starts with
This is one of those questions that I'm sure will have a quick answer
I'm a little bit new to Actionscript, but I can't figure this one out.
this one is really easy. I'm trying to create a Regular Expression that will
I guess no one will have a definative answer to this but considered predictions
The typical Python threadpool will have a structure like this one: def run(self): while
Okay, so this one may be difficult but I will do my best to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.