Avatar of Errol Farro
Errol FarroFlag for Aruba

asked on 

Add new column from complex SQL

To an existing sql result, I must add a new column. The new column is retrieved from a complex SQL

SQL result 1 (existing sql result)
==========================
select id, amount from MortgEdit1 where id = 1234

ID              Amount
1234      750.00


SQL result 2 (result of complex SQL)
=====================================
      DECLARE @Names VARCHAR(1000)
      
      SELECT
            @Names = COALESCE(@Names,'') + ciLastName + ',' + ciFirstName + ';'
      from
            mortgMaster
      inner join
            mortgdetail
      on
            mmid = mdmmId
      inner join
            contactinfo
      on
            mdidn = ciId
      where
            mdActive = 'Active' and
            mmActive = 'Active' and
            mdParentName = 'Applicants' and
            mmId = 12345

      
      SET @Names = Case @Names when null then null else (case LEN(@Names) when 0 then @Names else LEFT(@Names, LEN(@Names) - 1) end ) end
      SELECT @Names AS Names

Names
John; Carol; Jack


Result for which I am after
===========================
ID              AMount      Names
1234      750.00      John; Carol; Jack
Microsoft SQL Server

Avatar of undefined
Last Comment
Brian Crowe
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

How does MortgEdit1.id relate to the "complex SQL"?
ASKER CERTIFIED SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Blurred text
THIS SOLUTION IS 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
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo