Using variables in View object | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Using variables in View object

Hi, Is it possible to do any programming in the View object, for example, in the code snippet given below, I would like to find out the date manually and execute an SQL statement based on that. I cannot call any procedure before running this view to store the data in a temp. table and refer it from view. Create View dbo.vw_GetAvgPrevYear
as declare @dt_LastYearDate as datetime
set @dt_LastYearDate = ‘2007-06-25 20:39:00’ select * from Employee
where ProcessDate = @dt_LastYearDate go Please give me your suggestions, thank you. Regards,
Devendran R
You cant use variables in a view. Use procedure or function instead Madhivanan Failing to plan is Planning to fail
Of course you can create a view that works with relative criteria, like ‘today’ or ‘last month’.
]]>