473,387 Members | 3,801 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,387 software developers and data experts.

wrong result set

Hello all,

I have the following t-sql batch:
create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
set @p_date1 = isnull(@p_date1, <some expression>)
set @p_date2 = isnull(@p_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @p_date1 and
date2 <= @p_date2 and
(
date1 >= @p_date1 or
date2 >= @p_date2
)
end
go

exec stp_test

This gives a WRONG resultset.

When I replace the variables with hardcoded values in the right format, the
returned result set is CORRECT, as follows

where
date1 <= 'hard coded date value 1' and
date2 <= 'hard coded date value 2' and
(
date1 >= 'hard coded date value 1' or
date2 >= 'hard coded date value 2'
)

When I elimate the derived table with a temporary table, the returned result
set is CORRECT

When I store the parameters in a local variable, and use the local variable,
the returned result set is CORRECT, as follows

create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
declare @l_date1 datetime
declare @l_date2 datetime

set @l_date1 = @p_date1
set @l_date2 = @p_date2

set @l_date1 = isnull(@l_date1, <some expression>)
set @l_date2 = isnull(@l_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @l_date1 and
date2 <= @l_date2 and
(
date1 >= @l_date1 or
date2 >= @l_date2
)
end
go

When I put less columns in the select list, the returned result set is
CORRECT, it doesnt make sense wich columns I remove from the select list.

The tables are not small (500.000 rows) and also is the result set. I use
this construction elsewhere, on other table combinations, but dont have
problems. So the content of the data makes difference.

Seems to me as a bug.

My question is: Can I say the derived table is instable in SQL server and
causes the problem of the wrong result set here?

Peter

Apr 16 '06 #1
3 2614
Peter wrote:
Hello all,

I have the following t-sql batch:
create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
set @p_date1 = isnull(@p_date1, <some expression>)
set @p_date2 = isnull(@p_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @p_date1 and
date2 <= @p_date2 and
(
date1 >= @p_date1 or
date2 >= @p_date2
)
end
go

exec stp_test

This gives a WRONG resultset.

When I replace the variables with hardcoded values in the right format, the
returned result set is CORRECT, as follows

where
date1 <= 'hard coded date value 1' and
date2 <= 'hard coded date value 2' and
(
date1 >= 'hard coded date value 1' or
date2 >= 'hard coded date value 2'
)

When I elimate the derived table with a temporary table, the returned result
set is CORRECT

When I store the parameters in a local variable, and use the local variable,
the returned result set is CORRECT, as follows

create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
declare @l_date1 datetime
declare @l_date2 datetime

set @l_date1 = @p_date1
set @l_date2 = @p_date2

set @l_date1 = isnull(@l_date1, <some expression>)
set @l_date2 = isnull(@l_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @l_date1 and
date2 <= @l_date2 and
(
date1 >= @l_date1 or
date2 >= @l_date2
)
end
go

When I put less columns in the select list, the returned result set is
CORRECT, it doesnt make sense wich columns I remove from the select list.

The tables are not small (500.000 rows) and also is the result set. I use
this construction elsewhere, on other table combinations, but dont have
problems. So the content of the data makes difference.

Seems to me as a bug.

My question is: Can I say the derived table is instable in SQL server and
causes the problem of the wrong result set here?

Peter

Please could you post some working code to reproduce the problem
(CREATE TABLE and INSERTs included). Also tell us what version, edition
and service pack you are using. That's essential information if you
think you've found a bug. "Wrong result" is also not a good description
of the problem. Show us or explain what result you expected and what
you actually got.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Apr 16 '06 #2
David,

I am not able now to post insert and the final code. It is too much for this
newsgroup. When I have to put real data, I have to encrypt it also. Maybe
then the behavior als changing too.

I dont get an errormessage. The problem is, not all results are in the
resultset I expected. My expectation is correct, because, if I change
something as i stated, the resultset is like expected.

I use MS SQL Server 2000 sp4. No hotfixes.

Thank you David.

"David Portas" <RE****************************@acm.org> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com...
Peter wrote:
Hello all,

I have the following t-sql batch:
create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
set @p_date1 = isnull(@p_date1, <some expression>)
set @p_date2 = isnull(@p_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @p_date1 and
date2 <= @p_date2 and
(
date1 >= @p_date1 or
date2 >= @p_date2
)
end
go

exec stp_test

This gives a WRONG resultset.

When I replace the variables with hardcoded values in the right format,
the
returned result set is CORRECT, as follows

where
date1 <= 'hard coded date value 1' and
date2 <= 'hard coded date value 2' and
(
date1 >= 'hard coded date value 1' or
date2 >= 'hard coded date value 2'
)

When I elimate the derived table with a temporary table, the returned
result
set is CORRECT

When I store the parameters in a local variable, and use the local
variable,
the returned result set is CORRECT, as follows

create procedure stp_test
(
@p_date1 as datetime = null,
@p_date2 as datetime = null
)
as begin
declare @l_date1 datetime
declare @l_date2 datetime

set @l_date1 = @p_date1
set @l_date2 = @p_date2

set @l_date1 = isnull(@l_date1, <some expression>)
set @l_date2 = isnull(@l_date2, <some other expression>)

select
<a lot of columns>
from
<some table>
inner join <some other table> on <expression>
inner join <dirived table> on <expression>
where
date1 <= @l_date1 and
date2 <= @l_date2 and
(
date1 >= @l_date1 or
date2 >= @l_date2
)
end
go

When I put less columns in the select list, the returned result set is
CORRECT, it doesnt make sense wich columns I remove from the select list.

The tables are not small (500.000 rows) and also is the result set. I use
this construction elsewhere, on other table combinations, but dont have
problems. So the content of the data makes difference.

Seems to me as a bug.

My question is: Can I say the derived table is instable in SQL server and
causes the problem of the wrong result set here?

Peter

Please could you post some working code to reproduce the problem
(CREATE TABLE and INSERTs included). Also tell us what version, edition
and service pack you are using. That's essential information if you
think you've found a bug. "Wrong result" is also not a good description
of the problem. Show us or explain what result you expected and what
you actually got.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--

Apr 16 '06 #3
Peter (so*****@someplace.com) writes:
My question is: Can I say the derived table is instable in SQL server and
causes the problem of the wrong result set here?


No, that would be to jump to conclusion. The cause for the problem is
likely to be much more specific. But since you did not include the actual
code, nor the underlying tables, there is not information enough to
recreate the problem. (And most likely tables and queries would not be
sufficient, as the data volumes may be required to get the incorrect
query plan that you apparently get.)

If you get this problem with SQL 2005, I suggest that you try extract
the tables to a database of its own, and ensure that the problem appears
there. Then submit a bug on http://lab.msdn.microsoft.com/ProductFeedback/.
If the data is not sensitive, you could attach the database to the bug.
Else just say in the error report that the database is available on
request. Obviously, the bug report should include information about what is
wrong about the result set.

If you get this problem with SQL 2000, I don't think there much that can
be done about it, since there apparently is a workaround. But if you are
able to reproduce the problem with a minimal set of data, so that you could
compose a script that creates tables, populates them and creates the
procedure you can post it to the newsgroup if you like. If nothing else,
people here can investigate if the problem is in SQL 2005 as well.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Apr 16 '06 #4

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

Similar topics

9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
5
by: Krisnamourt Correia via SQLMonster.com | last post by:
I have one query that executes many times in a week. I created one Maintenances plan that Rebuild all index in my Database that has been executed at 23:40 Saturday until stop finished at Sunday. ...
2
by: Abby | last post by:
I need to do 8 bits 2's complement checksum, so I wrote code in order to see if the checksum calculation is correct. ===========================================================================...
10
by: andrew browning | last post by:
i have overlaoded all of my arithmetic operators but all are functioning as multiplication. below is a sample of the addition operator: Rational operator + (const Rational& r1, const Rational&...
318
by: jacob navia | last post by:
Rcently I posted code in this group, to help a user that asked to know how he could find out the size of a block allocated with malloc. As always when I post something, the same group of people...
3
by: Siong.Ong | last post by:
Dear all, my PHP aims to update a MySQL database by selecting record one by one and modify then save. Here are my PHP, but I found that it doesnt work as it supposed to be, for example, when...
7
by: fl | last post by:
Hi, I am learning C++ with C++ primer written by Lippman. The first output line: cout << s1 << endl; works right. The second is wrong. I find the problem is that s1 is destroyed in the call from...
27
by: Dave | last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU compilers. I then decided to try to use Sun's compiler. The Sun Studio 12 compiler reports the following code, which is in...
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.