Sql Sinamico
Publicado por Ignacio Monserrat (7 intervenciones) el 08/07/2008 01:40:37
Mi stored procedure lo tengo asi:
use NuevaBase
go
if exists(select routine_name from information_schema.routines where
routine_type='procedure' and routine_name='grp')
drop procedure grp
go
create procedure grp(@rating varchar(14),@tv varchar(10),@marca int)
as
declare @sqlstring as nvarchar(1000)
set @sqlstring='select sum(t_212)as G from [dbo].['+@rating+'] where '+
@tv+'.comercial_id in(select comercial_id from comerciales where producto_id in' +
'(select producto_id from productos where marca_id='+convert(nvarchar(10),@marca) +) '))'+'and '+@rating+ '.dia_hora='+@tv+ '.dia_hora and '+@rating+ '.vehiculo_id=' +@tv+ '.vehiculo_id'
execute sp_executesql @sqlstring
go
exec grp 'rating_2007_01','tv_2007_01',30
Al momento de correrlo me sale el sgte mensaje:
Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'tv_2007_01' does not match with a table name or alias name used in the query.
Pero esa tabla si existe en mi base de datos
use NuevaBase
go
if exists(select routine_name from information_schema.routines where
routine_type='procedure' and routine_name='grp')
drop procedure grp
go
create procedure grp(@rating varchar(14),@tv varchar(10),@marca int)
as
declare @sqlstring as nvarchar(1000)
set @sqlstring='select sum(t_212)as G from [dbo].['+@rating+'] where '+
@tv+'.comercial_id in(select comercial_id from comerciales where producto_id in' +
'(select producto_id from productos where marca_id='+convert(nvarchar(10),@marca) +) '))'+'and '+@rating+ '.dia_hora='+@tv+ '.dia_hora and '+@rating+ '.vehiculo_id=' +@tv+ '.vehiculo_id'
execute sp_executesql @sqlstring
go
exec grp 'rating_2007_01','tv_2007_01',30
Al momento de correrlo me sale el sgte mensaje:
Server: Msg 107, Level 16, State 3, Line 1
The column prefix 'tv_2007_01' does not match with a table name or alias name used in the query.
Pero esa tabla si existe en mi base de datos
Valora esta pregunta


0