Avatar of Amanda Walshaw
Amanda Walshaw
Flag for Australia asked on

One field reference in a view result for two different tables

Hello,
I have written a view which shows all the results depending on the description type then shows the reference number, it is displaying correctly but how can I just show the result in the same column ie as CemCRem ref (without referring to burial or cremation)

--Cremation or Burial details
case k.Description when 'White' then  j.BOOKINGNO end AS [Reference White],
case k.Description when 'Black' then f.BOOKINGNO end AS [Reference Black],
      
Note the booking reference comes from different tables.  but in the view I want to show it as one field in the view as 'Reference' not Reference White Reference Black
Microsoft SQL ServerMicrosoft SQL Server 2008SQL

Avatar of undefined
Last Comment
Amanda Walshaw

8/22/2022 - Mon
keyu

take one temp table store all values inside itand fire /execute select query.

create table #temp( refnumber varchar(4000),refnumber1 varchar(4000))

insert into #temp select id,case k.Description when 'White' then  j.BOOKINGNO end AS [Reference White] from table_name

insert into #temp select id,case k.Description when 'Black' then f.BOOKINGNO end AS [Reference Black] from table_name

select refnumber ,refnumber1  from #temp
ASKER CERTIFIED SOLUTION
jensonpp

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
TempDBA

Can you post a sample of data, how you are getting the result now and how you want all in data format? That will help us to better get the requirement.
Amanda Walshaw

ASKER
that worked thank you;
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes