I don’t need to join in a whole table, but just want a value from the table returned in my select list (but other tables are joined for other items). It’s giving me an error…incorrect syntax near select
select c.id as caseId ,sc.date ,select id from Queues where name = 'BB' as queueId --incorrect syntax near select..but just need this id without joining with other data FROM dbo.Cases c INNER JOIN Extensions sc on sc.id=c.id Cases: id area user 1 here Michele 2 there George Extensions: id subArea line 1 hereThere b 2 ThereHere c
I’m having trouble searching online for this.
Advertisement
Answer
Assuming the scalar subquery returns one row at most, you can enclose it between parenthesis, as in:
select c.id as caseId ,sc.date ,(select id from Queues where name = 'BB') as queueId FROM dbo.Cases c INNER JOIN Extensions sc on sc.id=c.id
If the scalar subquery returns more than one row the whole query will crash.