Help with subquery select Sql Server

1

Hi, I have a query to a SQL Server function and I need to show fields in a table in that same query. I did it like that but it shows me error. I also underline the query in red and a message appears that says: An insufficient number of arguments was specified for the procedure or function function1

Select * from dbo.funcion1('A','2014-07-01','2014-07-01','2018-04-30',0,1, (Select campo1, campo2 from tabla where Cod_user='101'), '101',0) Order by Cod_lin

Error:

  

Mens. 116, Level 16, State 1, Line 8       You can only specify an expression in the selection list when the subquery is not specified with EXISTS.       Mens. 313, Level 16, State 3, Line 8       An insufficient number of arguments was provided for the procedure or function function1

    
asked by fredyfx 30.04.2018 в 18:57
source

1 answer

1

Deal with a top 1

Select * 
from dbo.funcion1 ('A','2014-07-01','2014-07-01','2018-04-30',0,1, 
(  Select top 1 campo1
   from tabla where Cod_user='101' ), 
(  Select top 1 campo2
   from tabla where Cod_user='101' ),'101',0) 
Order by Cod_lin

Since the subquery is returning more than one value, the function does not allow it unless you join with it

    
answered by 30.04.2018 / 20:35
source