Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Dynamic Pivot return value is integer not the tabl

Author  Topic 

itslucky
Starting Member

2 Posts

Posted - 2012-08-02 : 07:43:56
Hi,
I have created a Stored Procedure in which I have used the dynamic pivot so it will get the dynamic columns.

and I am storing the result in a Variable.
when i execute the variable it display the required Results.
BUT
when I execute the stored procedure it Display the records But also return the int value '0'

So I just unable to use the returned Records.

Can you please help me to solve this I want to return the records as a Table.

My Code is as bellow (It is working fine but it didn't return the Records as table)

/////////////////////////////////////////////////////////////////////



ALTER PROCEDURE [dbo].[SelectAllContractorRates]
@ContractorID varchar(max),
@JobSeverityID varchar(max)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

DECLARE @query1 nvarchar(max)
DECLARE @time nvarchar(max)
--select * from JobRateTypes

SELECT @time= STUFF(( SELECT DISTINCT
'],[' + ltrim(JobRateType)

FROM JobRateTypes

ORDER BY '],[' + ltrim(JobRateType)
FOR XML PATH('')
), 1, 2, '') + ']'



SET @query1 =
'
SELECT
CASE WHEN FirstHour = 1 THEN ''First Hour'' ELSE ''Additional Hours'' END AS [Time],
*
FROM
(
SELECT [JobRateType],Rate,FirstHour
FROM
ContractorDefaultRates cr
INNER JOIN JobRateTypes jrt ON
cr.JobRateTypeID = jrt.JobRateTypeID
INNER JOIN JobSeverities js ON
cr.JobSeverityID = js.JobSeverityID
WHERE
contratorID = '+@ContractorID+' AND
js.JobSeverityID = '+@JobSeverityID+' AND
jrt.BankHoliday = 0
) p PIVOT ( SUM([Rate])
FOR [JobRateType]
IN ('+@time+')
) AS pvt
ORDER BY [Time] DESC


'
--execute (@query1);
exec sp_executesql @query1;

END



Regards,

>>>>>>>>~*Lucky*~<<<<<<<<

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-02 : 09:53:49
what do you mean by it doesnt return as a table?
are you trying to call this from an application ? how are you trying to grab the values from resultset of this procedure?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -