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

  • Home
  • SEARCH
  • 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 6572935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:04:07+00:00 2026-05-25T15:04:07+00:00

I am trying to run a query that contains a pending assignment task. The

  • 0

I am trying to run a query that contains a pending assignment task. The pending assignment table contain rows “new drug” and “current drug” that reference to the same drug dose row in another table. When I run a query like below, I get no results (notice that I am joining both the new and current drug to the same row dose ID:

SELECT D_PENDING_POCKET_ASSIGN.Station_Id,
   D_PENDING_POCKET_ASSIGN.Cabinet_Num,
   D_PENDING_POCKET_ASSIGN.Drawer_Num,
   D_PENDING_POCKET_ASSIGN.Pocket_Num,
   D_PENDING_POCKET_ASSIGN.Assignment_Type,
   D_PENDING_POCKET_ASSIGN.Requested_By,
   D_PENDING_POCKET_ASSIGN.Requested_Dttm,
   D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id,
   AHI_DRUG_DOSE.Drug_Display_Name,
   D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id 
   FROM CRX_DATA.dbo.D_PENDING_POCKET_ASSIGN D_PENDING_POCKET_ASSIGN,
   CRX_DATA.dbo.AHI_DRUG_DOSE AHI_DRUG_DOSE
   WHERE (D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id =
       AHI_DRUG_DOSE.Drug_Dose_Id)
   OR (D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id =
           AHI_DRUG_DOSE.Drug_Dose_Id)

However, when I run them separately, I get the desired results. See below:

SELECT D_PENDING_POCKET_ASSIGN.Station_Id,
   D_PENDING_POCKET_ASSIGN.Cabinet_Num,
   D_PENDING_POCKET_ASSIGN.Drawer_Num,
   D_PENDING_POCKET_ASSIGN.Pocket_Num,
   D_PENDING_POCKET_ASSIGN.Assignment_Type,
   D_PENDING_POCKET_ASSIGN.Requested_By,
   D_PENDING_POCKET_ASSIGN.Requested_Dttm,
   D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id,
   AHI_DRUG_DOSE.Drug_Display_Name
FROM CRX_DATA.dbo.D_PENDING_POCKET_ASSIGN D_PENDING_POCKET_ASSIGN,
   CRX_DATA.dbo.AHI_DRUG_DOSE AHI_DRUG_DOSE
WHERE (D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id =
       AHI_DRUG_DOSE.Drug_Dose_Id)

SELECT D_PENDING_POCKET_ASSIGN.Station_Id,
   D_PENDING_POCKET_ASSIGN.Cabinet_Num,
   D_PENDING_POCKET_ASSIGN.Drawer_Num,
   D_PENDING_POCKET_ASSIGN.Pocket_Num,
   D_PENDING_POCKET_ASSIGN.Assignment_Type,
   D_PENDING_POCKET_ASSIGN.Requested_By,
   D_PENDING_POCKET_ASSIGN.Requested_Dttm,
   AHI_DRUG_DOSE.Drug_Display_Name,
   D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id
FROM CRX_DATA.dbo.D_PENDING_POCKET_ASSIGN D_PENDING_POCKET_ASSIGN,
   CRX_DATA.dbo.AHI_DRUG_DOSE AHI_DRUG_DOSE
WHERE (D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id = AHI_DRUG_DOSE.Drug_Dose_Id)

I would like to know if there is a way to create a view by combining the two select queries into one?

Thank you

  • 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-05-25T15:04:08+00:00Added an answer on May 25, 2026 at 3:04 pm

    Your query, as written, will not likely work.

    WHERE (D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id =          AHI_DRUG_DOSE.Drug_Dose_Id)   
    AND (D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id =            AHI_DRUG_DOSE.Drug_Dose_Id) 
    

    You are asking SQL to find a record in the AHI_DRUG_DOSE table with the field Drug_Dose_ID equal to both the Current_drug_dose_id and the New_Drug_dose_Id. Unless those ID’s are the same, it is not possible to have one field contain both values…

    Try this instead.

    WHERE (D_PENDING_POCKET_ASSIGN.Current_Drug_Dose_Id =          AHI_DRUG_DOSE.Drug_Dose_Id)   
    OR (D_PENDING_POCKET_ASSIGN.New_Drug_Dose_Id =            AHI_DRUG_DOSE.Drug_Dose_Id) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to run an update query that updates one table based on rows
I am trying to run a query that selects values from a table using
I'm trying to run a LINQ to SQL query that returns a result in
I am trying to run a query on a dbase IV table from C#.
I'm getting this error when trying to run a query that inserts results into
I'm trying to run a query that has a few columns that are a
I have the following SQL query that I am trying to run inside Microsoft
I'm trying to run the following query, and I'm having trouble with the wildcard.
I'm currently trying to run a LINQ query over a MS SQL database. This
I'm trying to run a simple query with $this->db in Kohana, but am running

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.