declare @Date DateTime
set @Date='2012-04-16'
select s.sid,'Status'=case a.sid when isnull(a.sid,null)
then 'absent' else 'present' end from
student s left outer join (select * from absent where date=@Date) as a
on s.sid=a.sid
I have a sql query like this, and I need to create a view with this one…..is it possible..
I created a function for this like
CREATE FUNCTION dbo.Attendance (@Date DateTime)
RETURNS TABLE
AS
RETURN
(
select s.sid,'Status'=case a.sid when isnull(a.sid,null)
then 'absent' else 'present' end from
student s left outer join (select * from absent where date=@Date) as a
on s.sid=a.sid
)
the view is created successfully….but when I call the view like
select * from dbo.Attendance('2012-04-11')
it reports error like “Conversion failed when converting date and/or time from character string.”……how can I call this function
paramerterised views are allowed in MS Access but no serious db server will allow you to construct a view that requires a mandatory parameter.
your example describes a stored procedure which should be the implementation of choice for your requirement.
another way of meeting your requirement would be to keep your @Date parameter in another table, provided it’s there the view can refer to that and will return a row if the criteria is met