I tried to assign the values to a view using parameters but I'm getting the error:
'ALTER VIEW' must be the first statement in a query batch.
When using GO statement, its unable to access the variables.
How can I assign parameters to a view.
USE [DBNAME]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @CA_Removal varchar(max)
SET @CA_Removal=(SELECT value FROM spider.Configuration WHERE id='Removal')
GO
ALTER view [spider3].[View] WITH SCHEMABINDING
as
select
asa.id,
ase.common,
from
[spider].Activity asa
inner join
[spider].External ase
on
asa.primaryKey = ase.owner
where
asa.type = TRY_CONVERT(int, @CA_Removal)
When asa.type = 10 it works properly.
where asa.type = (select value FROM spider.Configuration WHERE id='Removal');GObetween your parameter definition and your view definition means they are in 2 completely separate batches and have no knowledge of each other.