Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update a view

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2011-02-14 : 10:50:34
Can a SQL Job update a view?

In my view I have a where inv_dt = 20100401.

Can I have a job that updates the view to change the where statement to where = year(getdate())+04+01

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2011-02-14 : 15:37:00
You don't need a job to change the view, simply make the Where clause use a calculation.

WHERE inv_dt = <calculated date condition>

How often does the date need to change, and what is the date supposed to change to so frequently you might need a job to change the view definition?



Poor planning on your part does not constitute an emergency on my part.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-02-14 : 16:01:45
Use ALTER VIEW instead of a SQL Agent job.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-02-15 : 05:30:24
If the date value is stored as an integer, you should use

where inv_dt = year(getdate())*10000+04*100+01

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -