October 18, 2007 at 12:13 pm
I have a view definition as below.
create view dbo.view1 as
select * from table1
where date1 >= '2007-01-01' or
date2 >= '2007-01-01' or
date3 >= '2007-01-01'
I'd like to define the date value '2007-01-01' as a constant and reframe the query like this :
create view dbo.view1 as
select * from table1
where date1 >= @dateConstant or
date2 >= @dateConstant or
date3 >= @dateConstant
I'd like to know how and where to define this @dateConstant and whether or not it's possible to do so.
October 18, 2007 at 12:22 pm
Is this something for you?
CREATE VIEW dbo.MyView AS
WITH MyCTE AS (
SELECT CAST('20070101' AS datetime) DateConstant
,T.*
FROM dbo.MyTable T
)
SELECT *
FROM MyCTE
WHERE date1 >= DateConstant
OR date2 >= DateConstant
OR date3 >= DateConstant
Best Regards,
Chris Büttner
October 18, 2007 at 4:36 pm
Most of us get pretty ticked off about people that multipost...
http://www.sqlservercentral.com/Forums/Topic412362-5-1.aspx
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply