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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:30:04+00:00 2026-06-02T01:30:04+00:00

I’ve tables and data as following, declare @tApplyProgram table (myID varchar(50), programID varchar(10), stTR

  • 0

I’ve tables and data as following,

declare @tApplyProgram table (myID varchar(50), programID varchar(10), stTR char(1) null)
insert into @tApplyProgram(myID,programID) values('1925','184');
insert into @tApplyProgram(myID,programID) values('4474','172');
insert into @tApplyProgram(myID,programID) values('8890','172');
insert into @tApplyProgram(myID,programID) values('5578','172');
insert into @tApplyProgram(myID,programID) values('2980','172');
insert into @tApplyProgram(myID,programID) values('2500','172');
insert into @tApplyProgram(myID,programID) values('1925','180');
insert into @tApplyProgram(myID,programID) values('5578','180');
/*
@tApplyProgram keep applicant and their programID
myID and programID is unique
*/

declare @tResult table (myID varchar(50), subjectCd varchar(50))
insert into @tResult values('1925','01')
insert into @tResult values('1925','02')
insert into @tResult values('1925','03')
insert into @tResult values('4474','03')
insert into @tResult values('4474','04')
insert into @tResult values('4474','05')
insert into @tResult values('5578','01')
insert into @tResult values('5578','02')
insert into @tResult values('5578','03')
insert into @tResult values('2980','01')
insert into @tResult values('2980','02')
/*
@tResult keep their applicant's result
myID and subjectCd is unique
*/


declare @tRulesD table (programID varchar(50), subjectCd varchar(50))
insert into @tRulesD values('172','05')
insert into @tRulesD values('172','02')
insert into @tRulesD values('172','15')
insert into @tRulesD values('184','01')
insert into @tRulesD values('184','02')
insert into @tRulesD values('184','03')
/*
@tRulesD keep programID rules and regulation
programID and subjectCd is unique
*/

If the programID being applied (@tApplyProgram) to meet requirements (@tRulesD), set stTR=1. If not meet requirements , set stTR=0. Else leave it to NULL

Expected results are shown as below,

myID  | programID  | stTR
------------------------------------
1925    184          1           /*1925 have rows in @tResult, and 184 have rows in @tRulesD. And, it's meet the requirements */
4474    172          0           /*4474 have rows in @tResult, and 172 have rows in @tRulesD. But, it's not meet the requirements */
8890    172          NULL        /*8890 don't have rows in @tResult*/
5578    172          0           /*5578 have rows in @tResult, and 172 have rows in @tRulesD. But, it's not meet the requirement*/
2980    184          0           /*2980 have rows in @tResult, and 184 have rows in @tRulesD. But. it's not meet the requirement*/
2500    172          NULL        /*2500 don't have rows in @tResult*/
1925    180          NULL        /*180 don't have rows in @tRulesD*/
5578    180          NULL        /*180 don't have rows in @tRulesD*/

Really need help to built the T-SQL. I’m stuck

  • 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-02T01:30:06+00:00Added an answer on June 2, 2026 at 1:30 am

    Here is subquery version of update. It works by connecting subqueries from result and rules given myid and programid respectively with a full outer join by subjectid column. This resultset is then tested for nulls (misses). If there is a miss max will return 1; if all values are matched returned value will be 0. This is valid for both sides. If there are no misses sum will give 0, and we return 1.
    If we found misses we still need to determine if all the values per a column are null. We do it by testing for not null value using count; if found, count will give 1, and if not it will give zero. If both sides have at least one not null value, we know that both rules and results have matching rows so we return 0. If not, return value is null.

    update @tApplyProgram
    set stTR = 
    (
      select
        case when max (case when u.subjectcd is null then 1 else 0 end) 
                + max (case when r.subjectcd is null then 1 else 0 end)
                = 0
             then 1
             else case when count (u.subjectcd) > 0
                        and count (r.subjectcd) > 0
                       then 0 
                       else null 
                   end
    
         end
        from (select * from @tResult r where r.myid = [@tApplyProgram].myid) r
        full outer join
             (select * from @tRulesD u where u.ProgramID = [@tApplyProgram].programid) u
         on r.subjectCd = u.subjectCd
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I

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.