473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

getdate() causes locks in views

Hello,

I have a problem with a view. The view reads as:

create view v_lds
as
select * from lds where dsdate > getdate() - 14

The idea being that the view only shows data which has modified within
the last 2 weeks. It works fine when viewing in through any tool.

However, when I have one application read from the view and a
different application write to the lds table directly, a dead lock
occurs.

If I modify the view to read:

create view v_lds
as
select * from lds where dsdate > '2003-08-15'

The problem disappears.

Any help would be much appreciated.

Thanks,

Allan Martin
Jul 20 '05 #1
2 3794
[posted and mailed, please reply in news]

Allan Martin (al*********@ntlworld.com) writes:
I have a problem with a view. The view reads as:

create view v_lds
as
select * from lds where dsdate > getdate() - 14

The idea being that the view only shows data which has modified within
the last 2 weeks. It works fine when viewing in through any tool.

However, when I have one application read from the view and a
different application write to the lds table directly, a dead lock
occurs.

If I modify the view to read:

create view v_lds
as
select * from lds where dsdate > '2003-08-15'

The problem disappears.


Not much to work from, I'm afraid.

What is likely to make a difference is that when you say

select * from lds where dsdate > '2003-08-15'

The optimizer can determine from the statistics how many rows in
lds it will hit, and therefore decide whether to use a non-clustered
index on that column or not. (You don't give any details on indexing,
but from the behaviour I guess that there such an index.)

When you instead put in an expression "getdate() - 14", SQL Server
does no longer have a value for it when building the query plan,
so it prefers to scan the table from left to right instead. This is
because, if many rows passes the where clause it would be slower
to use the index.

You should probably look into your index strategy. Many the index
on lds.dsdate should be clustered. But for a quick fix, you might
save the situation with an index hint to force use of the index
on lds.dsdate:

SELECT * FROM lds WITH (INDEX = lds_dsdate_ix) WHERE dsdate ...

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2
Yo can also try creating a row in a table with single column indexed
with getdate()-14 and convert the query as a join

Srinivas

al*********@ntlworld.com (Allan Martin) wrote in message news:<a6**************************@posting.google. com>...
Hello,

I have a problem with a view. The view reads as:

create view v_lds
as
select * from lds where dsdate > getdate() - 14

The idea being that the view only shows data which has modified within
the last 2 weeks. It works fine when viewing in through any tool.

However, when I have one application read from the view and a
different application write to the lds table directly, a dead lock
occurs.

If I modify the view to read:

create view v_lds
as
select * from lds where dsdate > '2003-08-15'

The problem disappears.

Any help would be much appreciated.

Thanks,

Allan Martin

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Konstantin Zakharenko | last post by:
Hello, Our QA team have running a lot of test scripts (for automated regression testing), they run them on the different databases (Oracle/MS SQL). Several of those tests are dependent on the...
2
by: Roy Padgett | last post by:
I have a combo box where users select the customer name and can either go to the customer's info or open a list of the customer's orders. The RowSource for the combo box was a simple pass-through...
10
by: Bill Edwards | last post by:
I'm trying to produce an array of working days but want to force Saturday and Sunday to return the date of the previous Friday, e.g. Sunday 9/12/04 should return Friday 9/10/04 and similarly...
8
by: Joe Weinstein | last post by:
Hi. create table joe(c1 integer not null, c2 integer not null) Two sessions: Session 1: BEGIN TRAN insert into joe (c1,c2) values (1,2)
1
by: shenanwei | last post by:
I have db2 v8.2.5 on AIX V5.3 with all the switches on Buffer pool (DFT_MON_BUFPOOL) = ON Lock (DFT_MON_LOCK) = ON Sort ...
4
by: jim_geissman | last post by:
According to MS, GetLocalTime() (in C++) is only accurate to approx a second, even though it reports milliseconds, and calling it twice and computing the interval can on occasion lead to a...
2
by: Ben.Combrink | last post by:
Hi I'm using DB2 V9.1.0 on SUSE Linux with kernel version 2.6.5. In the system I'm working on, there are several stored procedures which perform simple selects through different views. ...
6
by: Matik | last post by:
Hi, I have a funny situation. Within: MSSQL 2000 SP3, everything below described is running on same PC. there is a program running, which sends information to two other programs. This...
6
by: FFMG | last post by:
Hi, My timezone is GMT +2 So when I do a $date = getdate( 0 ); I get: $date = {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.