TSQL allocate variables from child result set to avoid repeating query

Is there a way to efficiently improve on the code below without repeating the query like this?

Note: There is a known number of elements for assigning arguments to in this case.

SELECT  @var0 = Field_A FROM Table_0 
JOIN Table_1 ON (Table_0.PK = Table_1.FK) 
WHERE Table_1.PK = 1 AND TABLE_0.Field_B = 1;

SELECT  @var1 = Field_A FROM Table_0 
JOIN Table_1 ON (Table_0.PK = Table_1.FK) 
WHERE Table_1.PK = 1 AND TABLE_0.Field_B = 2;

SELECT  @var2 = Field_A FROM Table_0 
JOIN Table_1 ON (Table_0.PK = Table_1.FK) 
WHERE Table_1.PK = 1 AND TABLE_0.Field_B = 3;

Answers


Something like this:

SELECT
    @var0 = MAX( CASE table_0.field_b WHEN 1 THEN field_a END )
    , @var1 =   MAX( CASE table_0.field_b WHEN 2 THEN field_a END )
    , @var2 =   MAX( CASE table_0.field_b WHEN 3 THEN field_a END )
FROM 
    table_0
JOIN
    table_1 
    ON 
        TABLE_0.PK = TABLE_1.FK

Need Your Help

Openx plugin development

php openx

I have just entered in the world of OpenX, and as figured out that new version is built with PLUGIN Framework. I have gone through the Openx plugin development documentation, but its quite bit

How can I set the exit code in Inno Setup?

inno-setup exit-code

I want to set the exit code for my installation, this way I will know why the installation was aborted. I'm using Inno Setup.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.