我有一个这样的存储过程:
ALTER procedure [dbo].[ParkingDeatailsReportnew]
@locid INTEGER, @startdate nvarchar(100),@enddate nvarchar(100)
as
begin
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(Vtype) from VType_tbl FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') ,1,1,'')
set @query = 'SELECT Date, ' + @cols + ' from ( select v.Vtype, convert(date, dtime) as Date
from Transaction_tbl t inner join VType_tbl v on t.vtid = v.vtid where dtime between ''' + @startdate + ''' and ''' + @enddate + '''and locid = ' + (select l.Locid from Location_tbl l)
+ ' ) d pivot ( count(Vtype) for Vtype in (' + @cols + ') ) p '
execute(@query)
end
执行此查询时出现以下错误:
需要未提供的参数“@locid”。我想从我的位置表中获取所有 locid