tediousjs / tedious

Node TDS module for connecting to SQL Server databases.
http://tediousjs.github.io/tedious/
MIT License
1.56k stars 443 forks source link

Issue with nested querys #925

Open luigicr18 opened 4 years ago

luigicr18 commented 4 years ago

I got a huge store procedure that received a list of zones, I have to create a string and then executed. The SP works fine but when I executed this on tedious I get null values the nested. SQL is something like

@nl         char(2) = char(13) + char(10)
SET @sql = N'SELECT 
    Clients.id, 
    Clients.name, 
    Sum(subQuery.value1),
    Sum(subQuery.value2)
FROM
    Clients LEFT OUTER JOIN (
    SELECT 
         sum(value1),
         sum(value2)
    from
        Data
   where
     date > date
     ' + @nl
IF(@zone IS NOT NULL)
    SELECT @sql += ' AND Data.Zone IN (' + @zone +')'+ @nl
)AS  subQuery

I get the id and name but value1 and value2 are null, if I execute this on SQL Server I got values for value1 and value2

IanChokS commented 4 years ago

Hi @luigicr18,

Just to clarify some things: Is the above example the stored procedure? If so, are you creating the stored procedure through Tedious and it's not working? If you are, what Tedious method are you using to submit this sql query?

Thanks

arthurschreiber commented 4 years ago

@luigicr18 Can you please post a complete example of how you're executing this SQL query, including all the calls you make via tedious? Without a fully reproducible sample, we can't even guess what might be going wrong here. 😞

IanChokS commented 4 years ago

@luigicr18 Any updates for us?