Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Different row counts between SQL management studio and Visual Studio

$
0
0

Hi

I'm pulling data from a NAV database using a stored procedure containing a Pivot (due to bad table design), the problem is my SQL management studio is returning 53 rows of records yet Visual studio is only returning 5.

I initially copied the query from management studio into VS to create my dataset, however after returning very few records I used a stored procedure instead.

Unfortunately the same result occurred, 5 records instead of 53,Is there something different between the two systems, perhaps VS doesn't like something in the Pivot?

Can anyone help?

Thanks

Charlie

CREATE

PROCEDURE [dbo].[PosReleaseTestPrepared]



--@Date AS DATETIME


AS

BEGIN


-- -- SET NOCOUNT ON added to prevent extra result sets from

-- -- interfering with SELECT statements.

-- SET NOCOUNT ON;

--    -- Insert statements for procedure here

--


DECLARE @colsNVARCHAR(MAX), @stmt NVARCHAR(MAX)SELECT        @cols=ISNULL(@cols+', ','')+'['+ ES.Code+']'


FROM          


(SELECT        Code

FROM            dbo.[Branston Live$Enquiry Step]

WHERE        [Enquiry Code]='PREPARED')AS ES

        

      

        

SELECT        @stmt='

    SELECT *

    FROM

    (SELECT PR.[Entry No_], PR.[Mobile User Code], PR.[Failure Step Code],PR.[Item No_], PR.[Customer No_] ,[Enquiry Step Code],  Value

     FROM dbo.[Branston Live$Positive Release] PR

      LEFT OUTER JOIN dbo.[Branston Live$Positive Release Step] PRS

       ON PR.[Entry No_] = PRS.[Positive Release Entry No_]

     WHERE PR.[Enquiry Code] = ''PREPARED'') PR

     PIVOT

     (

      MAX(VALUE)

      FOR [Enquiry Step Code] in ('


                                                                                                                                                                                         

+ @cols+')

     ) AS P'

EXECsp_executesql@stmt

    

    

    

    


END

GO


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>