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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:48:16+00:00 2026-05-24T18:48:16+00:00

Lets say I have this: Declare @passRefID as int Declare @passTextA as varchar Deckare

  • 0

Lets say I have this:

Declare @passRefID as int
Declare @passTextA as varchar
Deckare @oassTextB as varchar
Declare @passPropertyA as int
Declare @passPropertyB as int


Set @oassTextA = 'Joe'
Set @passTextB = 'Smith'
Set @passPropertyA = 21
Set @passPropertyB = 23

TSQL A:

Set @passRefID = Select Ref_ID from TableA where ID = 10

The Ref_ID returns a value of 50

Now I want to use that value in another select statement which returns any amount of rows.
It looks like this

TSQL B:

Select UserID from TableB where FK_RefID = @passRefID

So lets say it returns:

UserID
34
56
87

Now I want to create an update for TableC based on the UserID that return previously.

My TableC layout of records look like this:

ID,   UserID, PropertyDefinitionID, PropertyValue
265,  34,     21,                    Bob
266,  34,     23,                    Barker
271,  34,     55,                    bb@abc.com
628,  56,     21,                    Jane
629,  56,     23,                    Adams
635,  56,     55,                    ja@abc.com
901,  83,     21,                    Tom
905,  83,     23,                    Thumb
910,  83,     55,                    tt@abc.com

I know I can use:

Update TableC Set PropertyValue = @oassTextA Where UserID = 34 and PropertyDefinitionID = @passPropertyA
Update TableC Set PropertyValue = @oassTextB Where UserID = 34 and PropertyDefinitionID = @passPropertyB
Update TableC Set PropertyValue = @oassTextA Where UserID = 56 and PropertyDefinitionID = @passPropertyA
Update TableC Set PropertyValue = @oassTextB Where UserID = 56 and PropertyDefinitionID = @passPropertyB
Update TableC Set PropertyValue = @oassTextA Where UserID = 83 and PropertyDefinitionID = @passPropertyA
Update TableC Set PropertyValue = @oassTextB Where UserID = 83 and PropertyDefinitionID = @passPropertyB

But my problem is that in TSQL B, those rows returned could differ. There could be 1 row or 100 rows returned and the TableC is constructed a bit different from the norm.

How can I create a dynamic UPDATE statement based on the amount of rows return using the unique USERIDs and the way the TableC uses the PropertyDefinitionID?

Thanks for your assistance.

  • 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-24T18:48:18+00:00Added an answer on May 24, 2026 at 6:48 pm
    UPDATE  TableC
    SET     PropertyValue = CASE WHEN PropertyDefinitionID = @passPropertyA
                                 THEN @oassTextA
                                 ELSE @oassTextB
                            END
    WHERE   PropertyDefinitionID IN ( @passPropertyA, @passPropertyB )
            AND UserID IN (
            SELECT  B.UserID
            FROM    TableB AS B
                    INNER JOIN TableA AS A ON A.Ref_ID = B.FK_RefID
            WHERE   A.Id = 10 )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have this array, int[] numbers = {1, 3, 4, 9, 2};
Lets say i have this usercontrol public class test : UserControl { public int
So lets say I have this interface: public interface IBox { public void setSize(int
So lets say I have this code int my_static_int = 4; func(&my_static_int); I passed
Let's say I have this SQL query: declare @input varchar(20) select * from myTable
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
Lets say I have this code: <?php class hello { var $greeting = hello;
Lets say I have this class in foobar-shared.lib: class FooBar { std::string m_helloWorld; }
Lets say we have this code: bool KeepGoing = true; DataInThread = new Thread(new

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.