• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Nested select... how to retrieve a value based on concatenation of relative column name?

Select id,
'MainImageURL' = CASE [Image]
         WHEN '' THEN ''
         ELSE (Select [Image Filename] from [myImageTable] where sku = convert(varchar(50),[Image]))
      END

from myTable


It keeps returning all nulls... but if I hardcode a value in the where condition... it works as I expect it to


Select id,
'MainImageURL' = CASE [Image]
         WHEN '' THEN ''
         ELSE (Select [Image Filename] from [myImageTable] where sku = 'i3234gf321f90da')
      END

from myTable
0
rocketTendon
Asked:
rocketTendon
  • 2
1 Solution
 
ispalenyCommented:
Select id,
'MainImageURL' = CASE [Image]
         WHEN '' THEN ''
         ELSE [Image Filename]
      END
from myTable
left join myImageTable] on sku = convert(varchar(50),[Image])
0
 
ispalenyCommented:
Typpo "left join myImageTable]"=>"left join [myImageTable]"
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now