Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

Answered Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

  • Friday, December 07, 2012 9:08 PM
     
     
    Select TS.Session# AS SessionId,    
    (SELECT Dbo.DecryptString(LastName) + '', '' + Dbo.DecryptString(FirstName) as PatientName 
    FROM Persons.Informations WHERE PersonId =
    (SELECT PersonId FROM Patients.Informations 
    WHERE PatientId = TST.PatientId))
    From

    Transactions.Session TS
    INNER JOIN
    Transactions.Payment TP 
    ON TS.SessionId = TP.SessionId
    INNER JOIN
    Transactions.SessionTransaction TST 
    ON TST.PaymentId = TP.PaymentId

    this is how my query looks..What is wrong with my query?

All Replies

  • Friday, December 07, 2012 9:13 PM
     
     Answered Has Code

    Your query is returning two column in the select instead of concatenating them like it appears you are trying to do. Try changing the query to single quotes like this:

    Select TS.Session# AS SessionId,    
    (SELECT Dbo.DecryptString(LastName) + ', ' + Dbo.DecryptString(FirstName) as PatientName 
    FROM Persons.Informations WHERE PersonId =
    (SELECT PersonId FROM Patients.Informations 
    WHERE PatientId = TST.PatientId))
    From
    Transactions.Session TS
    INNER JOIN
    Transactions.Payment TP 
    ON TS.SessionId = TP.SessionId
    INNER JOIN
    Transactions.SessionTransaction TST 
    ON TST.PaymentId = TP.PaymentId


  • Friday, December 07, 2012 10:11 PM
     
      Has Code

    Barry Marshall's correct. Instead of 1 single quote there are 2 single quotes and so it's not concatenating and that SELECT statement is returning 2 columns (instead of one)

    Dbo.DecryptString(LastName),Dbo.DecryptString(FirstName)

    Try this example -

    SELECT 'a'+'',''+'b'
    SELECT 'a'+' , '+'b'


    Narsimha




    • Edited by Naarasimha Friday, December 07, 2012 10:15 PM
    • Edited by Naarasimha Friday, December 07, 2012 10:16 PM
    • Edited by Naarasimha Friday, December 07, 2012 10:18 PM
    •  
  • Saturday, December 08, 2012 12:13 PM
     
     Answered

    Hi Bindu.Vissa,

    Try this,

    Select TS.Session# AS SessionId,    
    (SELECT  Dbo.DecryptString(TOP 1 LastName) + ', ' + Dbo.DecryptString(TOP 1 FirstName) as PatientName
    FROM Persons.Informations WHERE PersonId =
    (SELECT TOP 1 PersonId FROM Patients.Informations
    WHERE PatientId = TST.PatientId))
    From

    Transactions.Session TS
    INNER JOIN
    Transactions.Payment TP
    ON TS.SessionId = TP.SessionId
    INNER JOIN
    Transactions.SessionTransaction TST
    ON TST.PaymentId = TP.PaymentId

    • Proposed As Answer by ameyjoe Saturday, December 08, 2012 12:19 PM
    • Marked As Answer by Iric WenModerator Monday, December 17, 2012 6:48 AM
    •