sql server - Pivot query error when added to a stored procedure, but runs OK in query builder window -
when run query in regular sql runs fine , correct results. now, want make query dynamic having user add dates such @dtfrom , @dtto date. these user supply dates application. now, i'm trying create stored procedure in sql server run this, these error ")" mis-placed. have looked @ , test portion of query without success.
create procedure dbo.[usp_cleaner_kg_per_date] @dtfrom datetime, @dtto datetime begin set nocount on; declare @query varchar(4000) declare @packdate varchar(2000) select @packdate = stuff(( select distinct '],[' + ((left(convert(varchar, packdate, 120), 10))) vw_cleanersummary2015 (packdate >= @dtfrom) , (packdate <= @dtto) order '],[' + ((left(convert(varchar, packdate, 120), 10))) xml path('') ), 1, 2, '') + ']' set @query = 'select * ( select id,kg,packdate vw_cleanersummary2015 group packdate,id,[kg/hr] )t pivot (sum(kg) packdate in ('+@packdate+')) pvt' execute (@query)
if of procedure code issue missing closing end
after execute
match opening begin
.
Comments
Post a Comment