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 7062737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:37:48+00:00 2026-05-28T04:37:48+00:00

I wrote the following query, but it appears to have an error, and I

  • 0

I wrote the following query, but it appears to have an error, and I was wondering if anyone could help me find it? I’m sorry about how long it is.

declare @Age int 
declare @Sex varchar(20)

set @Age=20
set @Sex='M'

select
    d.Dep_Name,d.Dep_Code,g.Group_Name,t.Test_Name,t.Test_Unit,(
    case 
        when at1.First_Age>=@Age and @Sex='M' then convert(varchar(10),at1.L_Bound_M_LessThan_1yr)+'-'+convert(varchar(10),at1.U_Bound_M_LessThan_1yr)
        when (at1.First_Age<@Age and at1.Second_Age>=@Age) and @Sex='M' then convert(varchar(10),at1.L_Bound_M_LessThan_20yr)+'-'+convert(varchar(10),at1.U_Bound_M_LessThan_20yr) 
        -- 5 more when statements

    ),
    st.Sub_Test_Name, st.Sub_Test_Unit, p.Result_Type, 
    p.Numeric_Value, p.Paragraph_Value ,p.Result_Normal,p.Sub_Test_ID,
    (
    case 
        when ast.First_Age>=@Age and @Sex='M' then convert(varchar(10),ast.L_Bound_M_LessThan_1yr)+'-'+convert(varchar(10),ast.U_Bound_M_LessThan_1yr) 
        --more WHEN's - mirrors the above case
    )
FROM 
    Patient_Test_3SC p LEFT JOIN
    ((Tests t INNER JOIN 
      Advanced_test_detail at1 on t.test_id=at1.test_id) LEFT JOIN 
     (Sub_Tests st INNER JOIN 
      Advanced_Sub_tests ast on st.sub_test_id=ast.sub_test_id) on t.Test_Code=st.Sub_Tests_Test_Code) 
         ON p.Test_ID=t.Test_ID 
    INNER JOIN Department d on p.Department_Code=d.Dep_Code 
    LEFT JOIN Groups g on p.Group_Code=g.Group_Code 
WHERE p.Patient_ID=@pid

I’ve had some errors in the code, and I’m not entirely sure where they’re from. Could someone please assist me in figuring out why I have an error in this SQL code?

  • 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-28T04:37:48+00:00Added an answer on May 28, 2026 at 4:37 am
    declare @Age int 
    declare @Sex varchar(20)
    declare @pid varchar(20)
    
    set @Age=20
    set @Sex='M'
    
    SELECT
        d.Dep_Name,d.Dep_Code,g.Group_Name,t.Test_Name,t.Test_Unit,
        st.Sub_Test_Name, st.Sub_Test_Unit, p.Result_Type, 
        p.Numeric_Value, p.Paragraph_Value ,p.Result_Normal,p.Sub_Test_ID,
        CASE 
            when at1.First_Age>=@Age and @Sex='M' then convert(varchar(10),at1.L_Bound_M_LessThan_1yr)+'-'+convert(varchar(10),at1.U_Bound_M_LessThan_1yr)
            when (at1.First_Age<@Age and at1.Second_Age>=@Age) and @Sex='M' then convert(varchar(10),at1.L_Bound_M_LessThan_20yr)+'-'+convert(varchar(10),at1.U_Bound_M_LessThan_20yr) 
            -- 5 more when statements
        END as 'var1',
        CASE 
            when ast.First_Age>=@Age and @Sex='M' then convert(varchar(10),ast.L_Bound_M_LessThan_1yr)+'-'+convert(varchar(10),ast.U_Bound_M_LessThan_1yr) 
            --more WHEN's - mirrors the above case
        END as 'var2'
    FROM 
        Patient_Test_3SC p LEFT JOIN
        ((Tests t INNER JOIN Advanced_test_detail at1 on t.test_id=at1.test_id) LEFT JOIN 
         (Sub_Tests st INNER JOIN Advanced_Sub_tests ast on st.sub_test_id=ast.sub_test_id) on t.Test_Code=st.Sub_Tests_Test_Code) 
        ON p.Test_ID=t.Test_ID 
        INNER JOIN Department d on p.Department_Code=d.Dep_Code 
        LEFT JOIN Groups g on p.Group_Code=g.Group_Code 
    WHERE p.Patient_ID=@pid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the following query, I think it's correct but I have a missing
I have the following problem. I wrote a query to get the date of
I wrote the following FQL query which should work but it seems to fail:
I wrote the following query to try and count the number of flights that
I have a stored procedure in which if I write the following query without
How to compare parts of date in Informix DBMS: I wrote the following query
Sorry about the title but I can't really think of a quick way of
I am just starting learning about Linq. I wrote some examples but there is
I wrote the following query: UPDATE king_in SET IN_PNSN_ALL_TP_CNTRCT_CD = IN_PNSN_ALL_TP_CNTRCT_CD + '3' WHERE
I have the following MySql query: select t1.* from Table1 t1 inner join Table2

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.