Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Thursday, March 22, 2012

bugs in subreport

I have a table contain a sub report . when I run on preview (visual studio), no problem . but when I run from my application , the report viewer just show "Report been generated" , never show the report .

after try and error I discover that when the query from main report return no records , plus the table contain a sub report , the problem occur only if you run it from your application using report viewer . not from visual studio . is this a bugs? anyway to resolve this or work around?

thks

a couple of things..

on your main report, you should probobaly set up a static dataset that always returns data... some like select from table where 1=1 or something like that. You can hide that information.

Secondly, besure to set up a description in the no rows property of the main and sub reports.

Bug?: left outer join in combination with a view

Hi,
there is a small test case (SQL Server 2000 - 8.00.760):
-- create a small table
create table test1 (nr int null)
insert into test1 values (1)
insert into test1 values (2)
-- now create a view
create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
If you perform this select, the isnull_jn col is always 'J',
although it should be 'N' in the second row:
select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn isnull_jn
-- -- --
1 J J
2 NULL J <<<=== error, should be N!
If you redefine the query to:
select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn case_jn
-- -- --
1 J J
2 NULL N <<== ok!
everything works fine.
Any suggestions?
--
markusOn Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:

>-- create a small table
>create table test1 (nr int null)
>insert into test1 values (1)
>insert into test1 values (2)
>-- now create a view
>create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
>If you perform this select, the isnull_jn col is always 'J',
>although it should be 'N' in the second row:
>select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn isnull_jn
>-- -- --
>1 J J
>2 NULL J <<<=== error, should be N!
>
>If you redefine the query to:
>select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn
'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn case_jn
>-- -- --
>1 J J
>2 NULL N <<== ok!
>everything works fine.
Hi Markus,
Nice one :-)
Looks like a bug to me. You might want to report it to MS.

>Any suggestions?
Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
COALESCE more portable. Plus, the support for ISNULL might be
discontinued in a future version of SQL Server.
2. COALESCE is more versatile. With COALESCE, you can get the first
non-NULL of as many arguments as you want. With ISNULL, the same can
only be achieved by nesting.
3. ISNULL apparently produces erroneous results when used in a left
outer join in combination with a view. A guy named Markus recently
posted about this in a newsgroup :-))
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi Hugo,
COALESCE has bug problems of it's own:
http://support.microsoft.com/defaul...kb;en-us;317527
If you want to play safe, use CASE for any non-trivial scenarios where you
would use ISNULL or COALESCE.
Jacco Schalkwijk
SQL Server MVP
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:e2sa80500of69g9q8e4dmijfcqjl9toenc@.
4ax.com...
> On Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:
>
'case_jn'[vbcol=seagreen]
> Hi Markus,
> Nice one :-)
> Looks like a bug to me. You might want to report it to MS.
>
> Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
> 1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
> COALESCE more portable. Plus, the support for ISNULL might be
> discontinued in a future version of SQL Server.
> 2. COALESCE is more versatile. With COALESCE, you can get the first
> non-NULL of as many arguments as you want. With ISNULL, the same can
> only be achieved by nesting.
> 3. ISNULL apparently produces erroneous results when used in a left
> outer join in combination with a view. A guy named Markus recently
> posted about this in a newsgroup :-))
>
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||On Wed, 21 Apr 2004 15:26:17 +0100, Jacco Schalkwijk wrote:

>Hi Hugo,
>COALESCE has bug problems of it's own:
>http://support.microsoft.com/defaul...kb;en-us;317527
>If you want to play safe, use CASE for any non-trivial scenarios where you
>would use ISNULL or COALESCE.
When I executed the repro query in that article, I didn't get the
error, but the (expected) value of 1. Apparantly, this bug is fixed in
Service Pack 3a.
But thanks for the pointer, anyway - it just shows that it pays to pay
attention to the results of your query. A complicated product like SQL
Server (or any other RDBMS) can never be completely bug-free.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)sql

Bug?: left outer join in combination with a view

Hi,
there is a small test case (SQL Server 2000 - 8.00.760):
-- create a small table
create table test1 (nr int null)
insert into test1 values (1)
insert into test1 values (2)
-- now create a view
create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
If you perform this select, the isnull_jn col is always 'J',
although it should be 'N' in the second row:
select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn isnull_jn
-- -- --
1 J J
2 NULL J <<<=== error, should be N!
If you redefine the query to:
select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn case_jn
-- -- --
1 J J
2 NULL N <<== ok!
everything works fine.
Any suggestions?
--
markusThat looks like a bug with ISNULL; I switched it to use COALESCE instead and
it fixed the problem...
Hopefully someone reading this knows how to submit a SQL bug report to MS?
"mark" <wimark@.smsNOSAPM.at> wrote in message
news:#EJS#RvJEHA.620@.tk2msftngp13.phx.gbl...
> Hi,
> there is a small test case (SQL Server 2000 - 8.00.760):
> -- create a small table
> create table test1 (nr int null)
> insert into test1 values (1)
> insert into test1 values (2)
> -- now create a view
> create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
> If you perform this select, the isnull_jn col is always 'J',
> although it should be 'N' in the second row:
> select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
> from test1 left outer join testview on test1.nr = testview.nr
> nr jn isnull_jn
> -- -- --
> 1 J J
> 2 NULL J <<<=== error, should be N!
>
> If you redefine the query to:
> select test1.nr, jn, case when jn is null then 'N' else jn end as
'case_jn'
> from test1 left outer join testview on test1.nr = testview.nr
> nr jn case_jn
> -- -- --
> 1 J J
> 2 NULL N <<== ok!
> everything works fine.
> Any suggestions?
> --
> markus
>|||ISNULL is kind of notoriously NOT the same thing as COALESCE and CASE, so I
was skeptical that this was really a bug. But below is a repro which uses
ISNULL with a view and an "inline view" or derived table.
Now despite any differences between INSULL and COALESCE, these 2 queries
should return the same data. They do not.
-- create a small table
create table test1 (nr int null)
insert into test1 values (1)
insert into test1 values (2)
-- now create a view
create view testview as select nr, 'J' jn from test1 where nr = 1
select
test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
from test1
left outer join (select nr, 'J' jn from test1 where nr = 1) testview
on test1.nr = testview.nr
where test1.nr=2
select
test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
from test1
left outer join testview
on test1.nr = testview.nr
where test1.nr=2
--
nr jn isnull_jn
2 N
(1 row(s) affected)
nr jn isnull_jn
2 J
(1 row(s) affected)
David
Should definitely return the same data
"Adam Machanic" <amachanic@.air-worldwide.nospamallowed.com> wrote in message
news:ebxMLqvJEHA.3120@.TK2MSFTNGP11.phx.gbl...
> That looks like a bug with ISNULL; I switched it to use COALESCE instead
and
> it fixed the problem...
> Hopefully someone reading this knows how to submit a SQL bug report to MS?
>
> "mark" <wimark@.smsNOSAPM.at> wrote in message
> news:#EJS#RvJEHA.620@.tk2msftngp13.phx.gbl...
> > Hi,
> >
> > there is a small test case (SQL Server 2000 - 8.00.760):
> >
> > -- create a small table
> > create table test1 (nr int null)
> > insert into test1 values (1)
> > insert into test1 values (2)
> > -- now create a view
> > create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
> >
> > If you perform this select, the isnull_jn col is always 'J',
> > although it should be 'N' in the second row:
> > select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
> > from test1 left outer join testview on test1.nr = testview.nr
> > nr jn isnull_jn
> > -- -- --
> > 1 J J
> > 2 NULL J <<<=== error, should be N!
> >
> >
> > If you redefine the query to:
> > select test1.nr, jn, case when jn is null then 'N' else jn end as
> 'case_jn'
> > from test1 left outer join testview on test1.nr = testview.nr
> > nr jn case_jn
> > -- -- --
> > 1 J J
> > 2 NULL N <<== ok!
> > everything works fine.
> >
> > Any suggestions?
> > --
> > markus
> >
> >
>|||On Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:
>-- create a small table
>create table test1 (nr int null)
>insert into test1 values (1)
>insert into test1 values (2)
>-- now create a view
>create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
>If you perform this select, the isnull_jn col is always 'J',
>although it should be 'N' in the second row:
>select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn isnull_jn
>-- -- --
>1 J J
>2 NULL J <<<=== error, should be N!
>
>If you redefine the query to:
>select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn case_jn
>-- -- --
>1 J J
>2 NULL N <<== ok!
>everything works fine.
Hi Markus,
Nice one :-)
Looks like a bug to me. You might want to report it to MS.
>Any suggestions?
Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
COALESCE more portable. Plus, the support for ISNULL might be
discontinued in a future version of SQL Server.
2. COALESCE is more versatile. With COALESCE, you can get the first
non-NULL of as many arguments as you want. With ISNULL, the same can
only be achieved by nesting.
3. ISNULL apparently produces erroneous results when used in a left
outer join in combination with a view. A guy named Markus recently
posted about this in a newsgroup :-))
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hi Hugo,
COALESCE has bug problems of it's own:
http://support.microsoft.com/default.aspx?scid=kb;en-us;317527
If you want to play safe, use CASE for any non-trivial scenarios where you
would use ISNULL or COALESCE.
--
Jacco Schalkwijk
SQL Server MVP
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:e2sa80500of69g9q8e4dmijfcqjl9toenc@.4ax.com...
> On Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:
> >-- create a small table
> >create table test1 (nr int null)
> >insert into test1 values (1)
> >insert into test1 values (2)
> >-- now create a view
> >create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
> >
> >If you perform this select, the isnull_jn col is always 'J',
> >although it should be 'N' in the second row:
> >select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
> >from test1 left outer join testview on test1.nr = testview.nr
> >nr jn isnull_jn
> >-- -- --
> >1 J J
> >2 NULL J <<<=== error, should be N!
> >
> >
> >If you redefine the query to:
> >select test1.nr, jn, case when jn is null then 'N' else jn end as
'case_jn'
> >from test1 left outer join testview on test1.nr = testview.nr
> >nr jn case_jn
> >-- -- --
> >1 J J
> >2 NULL N <<== ok!
> >everything works fine.
> Hi Markus,
> Nice one :-)
> Looks like a bug to me. You might want to report it to MS.
> >
> >Any suggestions?
> Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
> 1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
> COALESCE more portable. Plus, the support for ISNULL might be
> discontinued in a future version of SQL Server.
> 2. COALESCE is more versatile. With COALESCE, you can get the first
> non-NULL of as many arguments as you want. With ISNULL, the same can
> only be achieved by nesting.
> 3. ISNULL apparently produces erroneous results when used in a left
> outer join in combination with a view. A guy named Markus recently
> posted about this in a newsgroup :-))
>
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)|||On Wed, 21 Apr 2004 15:26:17 +0100, Jacco Schalkwijk wrote:
>Hi Hugo,
>COALESCE has bug problems of it's own:
>http://support.microsoft.com/default.aspx?scid=kb;en-us;317527
>If you want to play safe, use CASE for any non-trivial scenarios where you
>would use ISNULL or COALESCE.
When I executed the repro query in that article, I didn't get the
error, but the (expected) value of 1. Apparantly, this bug is fixed in
Service Pack 3a.
But thanks for the pointer, anyway - it just shows that it pays to pay
attention to the results of your query. A complicated product like SQL
Server (or any other RDBMS) can never be completely bug-free.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Bug?: left outer join in combination with a view

Hi,
there is a small test case (SQL Server 2000 - 8.00.760):
-- create a small table
create table test1 (nr int null)
insert into test1 values (1)
insert into test1 values (2)
-- now create a view
create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
If you perform this select, the isnull_jn col is always 'J',
although it should be 'N' in the second row:
select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn isnull_jn
-- -- --
1 J J
2 NULL J <<<=== error, should be N!
If you redefine the query to:
select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn'
from test1 left outer join testview on test1.nr = testview.nr
nr jn case_jn
-- -- --
1 J J
2 NULL N <<== ok!
everything works fine.
Any suggestions?
markus
On Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:

>-- create a small table
>create table test1 (nr int null)
>insert into test1 values (1)
>insert into test1 values (2)
>-- now create a view
>create view testview (nr, jn ) as select nr, 'J' from test1 where nr = 1
>If you perform this select, the isnull_jn col is always 'J',
>although it should be 'N' in the second row:
>select test1.nr, jn , isnull( jn, 'N') as 'isnull_jn'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn isnull_jn
>-- -- --
>1 J J
>2 NULL J <<<=== error, should be N!
>
>If you redefine the query to:
>select test1.nr, jn, case when jn is null then 'N' else jn end as 'case_jn'
>from test1 left outer join testview on test1.nr = testview.nr
>nr jn case_jn
>-- -- --
>1 J J
>2 NULL N <<== ok!
>everything works fine.
Hi Markus,
Nice one :-)
Looks like a bug to me. You might want to report it to MS.

>Any suggestions?
Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
COALESCE more portable. Plus, the support for ISNULL might be
discontinued in a future version of SQL Server.
2. COALESCE is more versatile. With COALESCE, you can get the first
non-NULL of as many arguments as you want. With ISNULL, the same can
only be achieved by nesting.
3. ISNULL apparently produces erroneous results when used in a left
outer join in combination with a view. A guy named Markus recently
posted about this in a newsgroup :-))
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Hi Hugo,
COALESCE has bug problems of it's own:
http://support.microsoft.com/default...b;en-us;317527
If you want to play safe, use CASE for any non-trivial scenarios where you
would use ISNULL or COALESCE.
Jacco Schalkwijk
SQL Server MVP
"Hugo Kornelis" <hugo@.pe_NO_rFact.in_SPAM_fo> wrote in message
news:e2sa80500of69g9q8e4dmijfcqjl9toenc@.4ax.com... [vbcol=seagreen]
> On Tue, 20 Apr 2004 18:32:32 +0200, mark wrote:
'case_jn'
> Hi Markus,
> Nice one :-)
> Looks like a bug to me. You might want to report it to MS.
>
> Yes. Don't use ISNULL. Use COALESCE instead. Three reasons:
> 1. COALESCE is ANSI-standard, ISNULL is proprietary. That makes
> COALESCE more portable. Plus, the support for ISNULL might be
> discontinued in a future version of SQL Server.
> 2. COALESCE is more versatile. With COALESCE, you can get the first
> non-NULL of as many arguments as you want. With ISNULL, the same can
> only be achieved by nesting.
> 3. ISNULL apparently produces erroneous results when used in a left
> outer join in combination with a view. A guy named Markus recently
> posted about this in a newsgroup :-))
>
> Best, Hugo
> --
> (Remove _NO_ and _SPAM_ to get my e-mail address)
|||On Wed, 21 Apr 2004 15:26:17 +0100, Jacco Schalkwijk wrote:

>Hi Hugo,
>COALESCE has bug problems of it's own:
>http://support.microsoft.com/default...b;en-us;317527
>If you want to play safe, use CASE for any non-trivial scenarios where you
>would use ISNULL or COALESCE.
When I executed the repro query in that article, I didn't get the
error, but the (expected) value of 1. Apparantly, this bug is fixed in
Service Pack 3a.
But thanks for the pointer, anyway - it just shows that it pays to pay
attention to the results of your query. A complicated product like SQL
Server (or any other RDBMS) can never be completely bug-free.
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)

Bug? No WSDL information fo a WEBMETHOD that points to a table-value function

Hello all,

I'm trying to create a web service that merely exposes a table value function. I have a dummy function that looks like this (in a DB called ReportingDB):

USE [ReportingDB];
DROP function [dbo].[TestFN];
GO
CREATE FUNCTION [dbo].[TestFN] ()
RETURNS
@.Table_Var TABLE (c1 int, c2 int)
AS
BEGIN
RETURN
END;
GO

My web service definition looks like this:

DROP ENDPOINT sql;
go

CREATE ENDPOINT sql
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
CLEAR_PORT = 90,
SITE = 'mypc'
)
FOR SOAP (
WEBMETHOD 'TestFN'
(name='ReportingDB.dbo.TestFN', SCHEMA=STANDARD),
WSDL = DEFAULT,
SCHEMA = STANDARD,
DATABASE = 'ReportingDB',
NAMESPACE = 'http://tempUri.org/'
);
go

Everything succeeds, however, the problem is that the TestFN function is not visible in the generated WSDL (http://mypc:90/sql?wsdl). If I do the same with a stored procedure instead of a function, then it works as expected, so it seems that I'm missing something or that this is a bug of SQL Server 2005.

Could somebody please shed some light on this issue?

Regards,

Ianier

Hi imj,

I think this comes from the type of function that you used. Your TestFN is a Table-valued function. I tried it with a Scalar-valued function, and it worked, the method is noted in the wsdl.

Here's my sample code:

DROP function [dbo].[TestFN];

GO

CREATE FUNCTION TestFN (@.DATE datetime)

RETURNS int

AS

BEGIN

DECLARE @.retVal int

SET @.retVal=1

RETURN(@.retVal)

END

GO

DROP ENDPOINT sql;

go

CREATE ENDPOINT sql

STATE = STARTED

AS HTTP(

PATH = '/sql/test',

AUTHENTICATION = (INTEGRATED ),

PORTS = ( CLEAR ),

CLEAR_PORT = 90,

SITE = 'mypc.domain.com'

)

FOR SOAP (

WEBMETHOD

'http://tempuri.org/'.'TestFN'

(NAME = 'ReportingDB.dbo.TestFN'),

BATCHES = ENABLED,

WSDL = DEFAULT

)

go

/*GRANT CONNECT ON ENDPOINT::sql TO [xxx\yyy]*/

Best regards,
Marcus

|||Thanks Marcus,

Then it may be a SQL Server bug, since the CREATE ENDPOINT command succeeds. Should I get no answer here, I will open a bug report about this.
The reason why I would like to use table-value functions instead of stored procedures is that, since the metadata for table-value functions results is known in advance, I was expecting to see a typed dataset (or array) in the WSDL. That would let me use my function from, say, InfoPath.
Regards,

Ianier|||Hi again,

FYI, I sent a bug report: http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=9e1e9b79-079d-40eb-b3f8-441432a26cbc
Nevertheless, it's hard for me to believe that such a serious issue escaped Microsoft's testing, so I'm still hoping that I'm missing something obvious.
Regards,

Ianier|||SQL Server's SOAP does not support table valued functions unfortunately. This is why it's not working. I found this out by talking to one of the testers. I cannot find where this is mentioned in the docs yet.|||Hello,

Thanks for the info.
That would be a major disapointment. This limitation is not documented and CREATE ENDPOINT reports no error, so this must be either a bug or an "undocumented odd behavior", which is the same.
IMO, not allowing table-value functions in a SOAP endpoint makes the WS feature extremely limited, if useful at all.
I'll come back to this group as soon as I get some feedback on my bug report.
Regards,

Ianier|||

The SQL 2005 Books Online documentation does have a statement stating that Table Value Functions are not supported in Native XML Web Services. Under the "Guidelines and Limitations in Native XML Web Services" topic (ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/8907005f-7f9b-4f53-80b8-f42729caf86b.htm), there's a bullet point saying:

Table valued user-defined functions are not supported.|||Thank you Jimmy,

In that case CREATE ENDPOINT should not succeed. This is definitely a bug.
Regards,

Ianier|||

Hi Ianier,

Thanks for the feedback.
SQL 2005 actually allows the "CREATE ENDPOINT" query to be executed before any of the webmethods are created.
ie.
CREATE ENDPOINT sql
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
CLEAR_PORT = 90,
SITE = 'mypc'
)
FOR SOAP (
WEBMETHOD 'TestFN'
(name='ReportingDB.dbo.TestFN', SCHEMA=STANDARD),
WSDL = DEFAULT,
SCHEMA = STANDARD,
DATABASE = 'ReportingDB',
NAMESPACE = 'http://tempUri.org/'
);
go

CREATE FUNCTION [dbo].[TestFN] ()
RETURNS
@.Table_Var TABLE (c1 int, c2 int)
AS
BEGIN
RETURN
END;
GO

In this scenario is would not be possible for the CREATE ENDPOINT query to verify what the webmethod is. You can argue that this should be a bug as well, but the current behavior provides a more flexible system. Suppose we were strict about requiring the webmethods to be created before the CREATE ENDPOINT query, what would happen if after the stored procedure or function was created, someone went and ALTER it or even DELETE it? Should the different endpoints to magically re-verify that the new version of the webmethod is still valid or even there?

The current mechanism allows SQL to verify at execution/run time that the methods are valid and the user has the proper permissions.

Hope that addresses some of your concerns.
Jimmy Wu [MSFT]

|||

Hi Jimmy,

Thanks for the information.

Common sense tells me that if the function exists and is not of a supported type (i.e. a table-value one) then CREATE ENDPOINT should fail. After all, CREATE ENDPOINT fails, for example, when trying to bind a WEBMETHOD to a view because views are not supported.

If someone ALTERs or DELETEs the function afterwards in a way that is not compatible with the endpoint, either of the following should happen:
Option 1: give an error explaining that the WEBMETHOD should be modified first (i.e. there's a dependency).
Option 2: delete the WEBMETHOD automatically and give a warning to the user.

Regards,

Ianier

sql

Bug? No WSDL information fo a WEBMETHOD that points to a table-value function

Hello all,

I'm trying to create a web service that merely exposes a table value function. I have a dummy function that looks like this (in a DB called ReportingDB):

USE [ReportingDB];
DROP function [dbo].[TestFN];
GO
CREATE FUNCTION [dbo].[TestFN] ()
RETURNS
@.Table_Var TABLE (c1 int, c2 int)
AS
BEGIN
RETURN
END;
GO

My web service definition looks like this:

DROP ENDPOINT sql;
go

CREATE ENDPOINT sql
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
CLEAR_PORT = 90,
SITE = 'mypc'
)
FOR SOAP (
WEBMETHOD 'TestFN'
(name='ReportingDB.dbo.TestFN', SCHEMA=STANDARD),
WSDL = DEFAULT,
SCHEMA = STANDARD,
DATABASE = 'ReportingDB',
NAMESPACE = 'http://tempUri.org/'
);
go

Everything succeeds, however, the problem is that the TestFN function is not visible in the generated WSDL (http://mypc:90/sql?wsdl). If I do the same with a stored procedure instead of a function, then it works as expected, so it seems that I'm missing something or that this is a bug of SQL Server 2005.

Could somebody please shed some light on this issue?

Regards,

Ianier

Hi imj,

I think this comes from the type of function that you used. Your TestFN is a Table-valued function. I tried it with a Scalar-valued function, and it worked, the method is noted in the wsdl.

Here's my sample code:

DROP function [dbo].[TestFN];

GO

CREATE FUNCTION TestFN (@.DATE datetime)

RETURNS int

AS

BEGIN

DECLARE @.retVal int

SET @.retVal=1

RETURN(@.retVal)

END

GO

DROP ENDPOINT sql;

go

CREATE ENDPOINT sql

STATE = STARTED

AS HTTP(

PATH = '/sql/test',

AUTHENTICATION = (INTEGRATED ),

PORTS = ( CLEAR ),

CLEAR_PORT = 90,

SITE = 'mypc.domain.com'

)

FOR SOAP (

WEBMETHOD

'http://tempuri.org/'.'TestFN'

(NAME = 'ReportingDB.dbo.TestFN'),

BATCHES = ENABLED,

WSDL = DEFAULT

)

go

/*GRANT CONNECT ON ENDPOINT::sql TO [xxx\yyy]*/

Best regards,
Marcus

|||Thanks Marcus,

Then it may be a SQL Server bug, since the CREATE ENDPOINT command succeeds. Should I get no answer here, I will open a bug report about this.
The reason why I would like to use table-value functions instead of stored procedures is that, since the metadata for table-value functions results is known in advance, I was expecting to see a typed dataset (or array) in the WSDL. That would let me use my function from, say, InfoPath.
Regards,

Ianier
|||Hi again,

FYI, I sent a bug report: http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?FeedbackId=9e1e9b79-079d-40eb-b3f8-441432a26cbc
Nevertheless, it's hard for me to believe that such a serious issue escaped Microsoft's testing, so I'm still hoping that I'm missing something obvious.
Regards,

Ianier
|||SQL Server's SOAP does not support table valued functions unfortunately. This is why it's not working. I found this out by talking to one of the testers. I cannot find where this is mentioned in the docs yet.|||Hello,

Thanks for the info.
That would be a major disapointment. This limitation is not documented and CREATE ENDPOINT reports no error, so this must be either a bug or an "undocumented odd behavior", which is the same.
IMO, not allowing table-value functions in a SOAP endpoint makes the WS feature extremely limited, if useful at all.
I'll come back to this group as soon as I get some feedback on my bug report.
Regards,

Ianier
|||

The SQL 2005 Books Online documentation does have a statement stating that Table Value Functions are not supported in Native XML Web Services. Under the "Guidelines and Limitations in Native XML Web Services" topic (ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/8907005f-7f9b-4f53-80b8-f42729caf86b.htm), there's a bullet point saying:

Table valued user-defined functions are not supported.|||Thank you Jimmy,

In that case CREATE ENDPOINT should not succeed. This is definitely a bug.
Regards,

Ianier
|||

Hi Ianier,

Thanks for the feedback.
SQL 2005 actually allows the "CREATE ENDPOINT" query to be executed before any of the webmethods are created.
ie.
CREATE ENDPOINT sql
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
CLEAR_PORT = 90,
SITE = 'mypc'
)
FOR SOAP (
WEBMETHOD 'TestFN'
(name='ReportingDB.dbo.TestFN', SCHEMA=STANDARD),
WSDL = DEFAULT,
SCHEMA = STANDARD,
DATABASE = 'ReportingDB',
NAMESPACE = 'http://tempUri.org/'
);
go

CREATE FUNCTION [dbo].[TestFN] ()
RETURNS
@.Table_Var TABLE (c1 int, c2 int)
AS
BEGIN
RETURN
END;
GO

In this scenario is would not be possible for the CREATE ENDPOINT query to verify what the webmethod is. You can argue that this should be a bug as well, but the current behavior provides a more flexible system. Suppose we were strict about requiring the webmethods to be created before the CREATE ENDPOINT query, what would happen if after the stored procedure or function was created, someone went and ALTER it or even DELETE it? Should the different endpoints to magically re-verify that the new version of the webmethod is still valid or even there?

The current mechanism allows SQL to verify at execution/run time that the methods are valid and the user has the proper permissions.

Hope that addresses some of your concerns.
Jimmy Wu [MSFT]

|||

Hi Jimmy,

Thanks for the information.

Common sense tells me that if the function exists and is not of a supported type (i.e. a table-value one) then CREATE ENDPOINT should fail. After all, CREATE ENDPOINT fails, for example, when trying to bind a WEBMETHOD to a view because views are not supported.

If someone ALTERs or DELETEs the function afterwards in a way that is not compatible with the endpoint, either of the following should happen:
Option 1: give an error explaining that the WEBMETHOD should be modified first (i.e. there's a dependency).
Option 2: delete the WEBMETHOD automatically and give a warning to the user.

Regards,

Ianier

Tuesday, March 20, 2012

BUG: Internal Server Error

Hi all!
MSSQL 7.0 and MSSQL2000 Server.
When running query:
create table t (id int primary key identity(1,1), f int, u varchar not null
default USER)
GO
create view v
as
select id, f
from t
where u = USER
GO
insert v (f)
select f
from v
group by f
GO
--
then get error:
Server: Msg 8624, Level 16, State 9, Line 1
Internal SQL Server error.
It's a bug?hi
just try this way
create table t
(id int primary key identity(1,1),
f int, u varchar not null
default 'USER')
GO
create view v
as
select id, f
from t
where u = 'USER'
GO
insert v (f) select f from t group by f
GO
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Roman S. Golubin" wrote:

> Hi all!
> MSSQL 7.0 and MSSQL2000 Server.
> When running query:
> --
> create table t (id int primary key identity(1,1), f int, u varchar not nul
l
> default USER)
> GO
> create view v
> as
> select id, f
> from t
> where u = USER
> GO
> insert v (f)
> select f
> from v
> group by f
> GO
> --
> then get error:
> --
> Server: Msg 8624, Level 16, State 9, Line 1
> Internal SQL Server error.
>
> It's a bug?
>
>|||Hi, Chandra!

> just try this way
> create table t
> (id int primary key identity(1,1),
> f int, u varchar not null
> default 'USER')
> GO
BOL. USER.
-> Use USER to return the current user's database username

BUG: Internal Server Error

Hi all!
MSSQL 7.0 and MSSQL2000 Server.
When running query:
create table t (id int primary key identity(1,1), f int, u varchar not null
default USER)
GO
create view v
as
select id, f
from t
where u = USER
GO
insert v (f)
select f
from v
group by f
GO
then get error:
Server: Msg 8624, Level 16, State 9, Line 1
Internal SQL Server error.
It's a bug?
hi
just try this way
create table t
(id int primary key identity(1,1),
f int, u varchar not null
default 'USER')
GO
create view v
as
select id, f
from t
where u = 'USER'
GO
insert v (f) select f from t group by f
GO
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
"Roman S. Golubin" wrote:

> Hi all!
> MSSQL 7.0 and MSSQL2000 Server.
> When running query:
> --
> create table t (id int primary key identity(1,1), f int, u varchar not null
> default USER)
> GO
> create view v
> as
> select id, f
> from t
> where u = USER
> GO
> insert v (f)
> select f
> from v
> group by f
> GO
> --
> then get error:
> --
> Server: Msg 8624, Level 16, State 9, Line 1
> Internal SQL Server error.
>
> It's a bug?
>
>
|||Hi, Chandra!

> just try this way
> create table t
> (id int primary key identity(1,1),
> f int, u varchar not null
> default 'USER')
> GO
BOL. USER.
-> Use USER to return the current user's database username

Bug: "ALTER TABLE *** WITH NOCHECK" does not work for SQL Server 2005

I wanted to turn off 'Enforce Foreign Key Constrain' using SQL. However, it did not work on the SQL Server 2005 database.

For example, running following SQL in Management Studio, and the result showed that 'Enforce Foreign Key Constrain' property for the newly created constraint was still enabled.

ALTER TABLE [dbo].[Tags] WITH NOCHECK ADD CONSTRAINT [FK_Tags_ChannelID] FOREIGN KEY([ChannelID]) REFERENCES [dbo].[Channels] ([ID])

Does anybody know any way to get around with this problem. It is quite important for my software.

Ps. with the SP1, problem remains the same.

ADD CONSTRAINT WITH NOCHECK is for not to fire the constraint against existing data in the table, when the constraint is created. If you want to disable the constraint you will need to run this statement as well:

ALTER TABLE dbo.Tags NOCHECK CONSTRAINT FK_Tags_ChannelID

"WITH NOCHECK" and "NOCHECK" have different meanings here even though they look similar.

|||

Thanks, That works very well.

What surprised me is that when I tried to generate the SQL script for a table with the disabled constraint using Management Tools, it did not give the other SQL statement. That is why I thought it is a bug of SQL Server 2005. Well, it IS a bug for the management tool then.

Thanks for the help

Monday, March 19, 2012

bug with TABLE variable??

Consider the following code but don't think about what it's supposed to do
as I've simplified it a lot.
The error I get is a syntax error when I try to save my proc so what this
proc is doing is not important.
DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
INSERT @.grpIds SELECT grp_id FROM tab_grp
DELETE
@.grpIds
FROM
@.grpIds
INNER JOIN tab_rub_deny
ON tab_rub_deny.grp_id = @.grpIds.grp_id
Error:
@.grpIds must be declared
If I replace the table variable by a normal table, there's no error any
more.
It seems to be a bug.
Should I use a temporary table then?
Thanks
HenriYou have to alias the table variable in the from clause, then you can
reference it in other parts of your statement:
DELETE
g
FROM
@.grpIds AS g
INNER JOIN tab_rub_deny
ON tab_rub_deny.grp_id = g.grp_id
--
Jacco Schalkwijk
SQL Server MVP
"Henri" <hmfireball@.hotmail.com> wrote in message
news:u7f%23PkS4EHA.2568@.TK2MSFTNGP11.phx.gbl...
> Consider the following code but don't think about what it's supposed to do
> as I've simplified it a lot.
> The error I get is a syntax error when I try to save my proc so what this
> proc is doing is not important.
> DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
> INSERT @.grpIds SELECT grp_id FROM tab_grp
> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>|||> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
Please see http://www.aspfaq.com/2475
Of particular interest:
"Table variables must be referenced by an alias, except in the FROM clause.
Consider the following two scripts: " [...]
--
http://www.aspfaq.com/
(Reverse address to reply.)
> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>|||It works now :-)
Thanks a lot for your help,
and thanks for the interesting resource link too :-)
Henri
"Henri" <hmfireball@.hotmail.com> a écrit dans le message de
news:u7f%23PkS4EHA.2568@.TK2MSFTNGP11.phx.gbl...
> Consider the following code but don't think about what it's supposed to do
> as I've simplified it a lot.
> The error I get is a syntax error when I try to save my proc so what this
> proc is doing is not important.
> DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
> INSERT @.grpIds SELECT grp_id FROM tab_grp
> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>

bug with TABLE variable??

Consider the following code but don't think about what it's supposed to do
as I've simplified it a lot.
The error I get is a syntax error when I try to save my proc so what this
proc is doing is not important.
DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
INSERT @.grpIds SELECT grp_id FROM tab_grp
DELETE
@.grpIds
FROM
@.grpIds
INNER JOIN tab_rub_deny
ON tab_rub_deny.grp_id = @.grpIds.grp_id
Error:
@.grpIds must be declared
If I replace the table variable by a normal table, there's no error any
more.
It seems to be a bug.
Should I use a temporary table then?
Thanks
Henri
You have to alias the table variable in the from clause, then you can
reference it in other parts of your statement:
DELETE
g
FROM
@.grpIds AS g
INNER JOIN tab_rub_deny
ON tab_rub_deny.grp_id = g.grp_id
Jacco Schalkwijk
SQL Server MVP
"Henri" <hmfireball@.hotmail.com> wrote in message
news:u7f%23PkS4EHA.2568@.TK2MSFTNGP11.phx.gbl...
> Consider the following code but don't think about what it's supposed to do
> as I've simplified it a lot.
> The error I get is a syntax error when I try to save my proc so what this
> proc is doing is not important.
> DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
> INSERT @.grpIds SELECT grp_id FROM tab_grp
> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>
|||> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
Please see http://www.aspfaq.com/2475
Of particular interest:
"Table variables must be referenced by an alias, except in the FROM clause.
Consider the following two scripts: " [...]
http://www.aspfaq.com/
(Reverse address to reply.)

> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>
|||It works now :-)
Thanks a lot for your help,
and thanks for the interesting resource link too :-)
Henri
"Henri" <hmfireball@.hotmail.com> a crit dans le message de
news:u7f%23PkS4EHA.2568@.TK2MSFTNGP11.phx.gbl...
> Consider the following code but don't think about what it's supposed to do
> as I've simplified it a lot.
> The error I get is a syntax error when I try to save my proc so what this
> proc is doing is not important.
> DECLARE @.grpIds TABLE (grp_id int PRIMARY KEY)
> INSERT @.grpIds SELECT grp_id FROM tab_grp
> DELETE
> @.grpIds
> FROM
> @.grpIds
> INNER JOIN tab_rub_deny
> ON tab_rub_deny.grp_id = @.grpIds.grp_id
> Error:
> @.grpIds must be declared
> If I replace the table variable by a normal table, there's no error any
> more.
> It seems to be a bug.
> Should I use a temporary table then?
> Thanks
> Henri
>
>

Bug when a table is adjacent to a matrix

I am trying to create a report that has a table adjacent to a matrix, with
the tops of each aligned together. I am trying to create a report where the
rows of the table and the matrix "line up" with each other. I have included
an example below where I have selected the customerID, orderID, and shipper
name from the rows of the Northwind orders table. I'd like to put the
customerID and orderID in a table that is adjacent to a matrix where each
column is a particular shipper. I'd like each row of this combination to
show the customerId, orderID with the shipper name in the appropriate
column.
HOWEVER -- When I render this report in HTML, the matrix terminates and
continues to the next page before the table does, causing the two to get out
of sync on the second page. I can't figure out a way to make the table and
the matrix stay aligned from the first page onto the second.
The report below should duplicate this behavior (I assume that you have the
Northwind DB installed).
Thanks,
Michael Carr
<?xml version="1.0" encoding="utf-8"?>
<Report
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
tion"
xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
<RightMargin>0.25in</RightMargin>
<Body>
<ReportItems>
<Table Name="table1">
<Height>0.5in</Height>
<ZIndex>1</ZIndex>
<Style />
<Header>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="textbox3">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
<FontWeight>700</FontWeight>
</Style>
<ZIndex>3</ZIndex>
<rd:DefaultName>textbox3</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>CustomerID</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="textbox4">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Right</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
<FontWeight>700</FontWeight>
</Style>
<ZIndex>2</ZIndex>
<rd:DefaultName>textbox4</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>Order ID</Value>
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
<RepeatOnNewPage>true</RepeatOnNewPage>
</Header>
<Details>
<TableRows>
<TableRow>
<Height>0.25in</Height>
<TableCells>
<TableCell>
<ReportItems>
<Textbox Name="CustomerID_1">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<rd:DefaultName>CustomerID_1</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!CustomerID.Value</Value>
</Textbox>
</ReportItems>
</TableCell>
<TableCell>
<ReportItems>
<Textbox Name="OrderID">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Right</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<rd:DefaultName>OrderID</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!OrderID.Value</Value>
</Textbox>
</ReportItems>
</TableCell>
</TableCells>
</TableRow>
</TableRows>
<Sorting>
<SortBy>
<SortExpression>=Fields!CustomerID.Value</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
<SortBy>
<SortExpression>=Fields!OrderID.Value</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
</Sorting>
</Details>
<DataSetName>DataSet1</DataSetName>
<Width>1.875in</Width>
<TableColumns>
<TableColumn>
<Width>1in</Width>
</TableColumn>
<TableColumn>
<Width>0.875in</Width>
</TableColumn>
</TableColumns>
</Table>
<Matrix Name="matrix1">
<Corner>
<ReportItems>
<Textbox Name="textbox1">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Left</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
<FontWeight>700</FontWeight>
</Style>
<ZIndex>4</ZIndex>
<rd:DefaultName>textbox1</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>CustomerID, OrderID</Value>
</Textbox>
</ReportItems>
</Corner>
<Height>0.5in</Height>
<Style />
<MatrixRows>
<MatrixRow>
<MatrixCells>
<MatrixCell>
<ReportItems>
<Textbox Name="CompanyName">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Left</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<rd:DefaultName>CompanyName</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=First(Fields!CompanyName.Value)</Value>
</Textbox>
</ReportItems>
</MatrixCell>
</MatrixCells>
<Height>0.25in</Height>
</MatrixRow>
</MatrixRows>
<MatrixColumns>
<MatrixColumn>
<Width>1.375in</Width>
</MatrixColumn>
</MatrixColumns>
<DataSetName>DataSet1</DataSetName>
<ColumnGroupings>
<ColumnGrouping>
<DynamicColumns>
<Grouping Name="matrix1_CompanyName">
<GroupExpressions>
<GroupExpression>=Fields!CompanyName.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<ReportItems>
<Textbox Name="CompanyName_1">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Left</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
<FontWeight>700</FontWeight>
</Style>
<ZIndex>3</ZIndex>
<rd:DefaultName>CompanyName_1</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!CompanyName.Value</Value>
</Textbox>
</ReportItems>
</DynamicColumns>
<Height>0.25in</Height>
</ColumnGrouping>
</ColumnGroupings>
<Width>3.25in</Width>
<Left>2in</Left>
<RowGroupings>
<RowGrouping>
<DynamicRows>
<Grouping Name="matrix1_CustomerID">
<GroupExpressions>
<GroupExpression>=Fields!CustomerID.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<Sorting>
<SortBy>
<SortExpression>=Fields!CustomerID.Value</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
</Sorting>
<ReportItems>
<Textbox Name="CustomerID">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Left</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>2</ZIndex>
<rd:DefaultName>CustomerID</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!CustomerID.Value</Value>
</Textbox>
</ReportItems>
</DynamicRows>
<Width>0.875in</Width>
</RowGrouping>
<RowGrouping>
<DynamicRows>
<Grouping Name="matrix1_OrderID">
<GroupExpressions>
<GroupExpression>=Fields!OrderID.Value</GroupExpression>
</GroupExpressions>
</Grouping>
<Sorting>
<SortBy>
<SortExpression>=Fields!OrderID.Value</SortExpression>
<Direction>Ascending</Direction>
</SortBy>
</Sorting>
<ReportItems>
<Textbox Name="textbox2">
<Style>
<PaddingLeft>2pt</PaddingLeft>
<TextAlign>Left</TextAlign>
<PaddingBottom>2pt</PaddingBottom>
<PaddingTop>2pt</PaddingTop>
<PaddingRight>2pt</PaddingRight>
</Style>
<ZIndex>1</ZIndex>
<rd:DefaultName>textbox2</rd:DefaultName>
<CanGrow>true</CanGrow>
<Value>=Fields!OrderID.Value</Value>
</Textbox>
</ReportItems>
</DynamicRows>
<Width>1in</Width>
</RowGrouping>
</RowGroupings>
</Matrix>
</ReportItems>
<Style />
<Height>3in</Height>
</Body>
<TopMargin>0.25in</TopMargin>
<DataSources>
<DataSource Name="Northwind">
<rd:DataSourceID>d83220b8-b683-4ff8-970d-134479e0e9d3</rd:DataSourceID>
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>data source=localhost;initial
catalog=Northwind</ConnectString>
<IntegratedSecurity>true</IntegratedSecurity>
</ConnectionProperties>
</DataSource>
</DataSources>
<Width>8in</Width>
<DataSets>
<DataSet Name="DataSet1">
<Fields>
<Field Name="OrderID">
<DataField>OrderID</DataField>
<rd:TypeName>System.Int32</rd:TypeName>
</Field>
<Field Name="CustomerID">
<DataField>CustomerID</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
<Field Name="CompanyName">
<DataField>CompanyName</DataField>
<rd:TypeName>System.String</rd:TypeName>
</Field>
</Fields>
<Query>
<DataSourceName>Northwind</DataSourceName>
<CommandText>SELECT
OrderID,
Orders.CustomerID,
Shippers.CompanyName FROM Orders
INNER JOIN Customers ON Customers.CustomerID = Orders.CustomerID
INNER JOIN Shippers ON Shippers.ShipperID = Orders.ShipVia</CommandText>
<rd:UseGenericDesigner>true</rd:UseGenericDesigner>
</Query>
</DataSet>
</DataSets>
<LeftMargin>0.25in</LeftMargin>
<rd:SnapToGrid>true</rd:SnapToGrid>
<rd:DrawGrid>true</rd:DrawGrid>
<rd:ReportID>82805f4c-8060-4d41-a1d0-bba1d089578f</rd:ReportID>
<BottomMargin>0.25in</BottomMargin>
<Language>en-US</Language>
</Report>This looks like a bug to me. I've let the dev team know. Thanks.
Possible workaround: Add explicit page breaks every N rows by adding an
outer grouping by =Ceiling(RowNumber(Nothing)/20)
--
This post is provided 'AS IS' with no warranties, and confers no rights. All
rights reserved. Some assembly required. Batteries not included. Your
mileage may vary. Objects in mirror may be closer than they appear. No user
serviceable parts inside. Opening cover voids warranty. Keep out of reach of
children under 3.
"Michael Carr" <mcarr@.umich.edu> wrote in message
news:%23hRajEjiEHA.1040@.TK2MSFTNGP09.phx.gbl...
> I am trying to create a report that has a table adjacent to a matrix, with
> the tops of each aligned together. I am trying to create a report where
the
> rows of the table and the matrix "line up" with each other. I have
included
> an example below where I have selected the customerID, orderID, and
shipper
> name from the rows of the Northwind orders table. I'd like to put the
> customerID and orderID in a table that is adjacent to a matrix where each
> column is a particular shipper. I'd like each row of this combination to
> show the customerId, orderID with the shipper name in the appropriate
> column.
> HOWEVER -- When I render this report in HTML, the matrix terminates and
> continues to the next page before the table does, causing the two to get
out
> of sync on the second page. I can't figure out a way to make the table and
> the matrix stay aligned from the first page onto the second.
> The report below should duplicate this behavior (I assume that you have
the
> Northwind DB installed).
> Thanks,
> Michael Carr
> <?xml version="1.0" encoding="utf-8"?>
> <Report
>
xmlns="http://schemas.microsoft.com/sqlserver/reporting/2003/10/reportdefini
> tion"
>
xmlns:rd="">http://schemas.microsoft.com/SQLServer/reporting/reportdesigner">
> <RightMargin>0.25in</RightMargin>
> <Body>
> <ReportItems>
> <Table Name="table1">
> <Height>0.5in</Height>
> <ZIndex>1</ZIndex>
> <Style />
> <Header>
> <TableRows>
> <TableRow>
> <Height>0.25in</Height>
> <TableCells>
> <TableCell>
> <ReportItems>
> <Textbox Name="textbox3">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> <FontWeight>700</FontWeight>
> </Style>
> <ZIndex>3</ZIndex>
> <rd:DefaultName>textbox3</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>CustomerID</Value>
> </Textbox>
> </ReportItems>
> </TableCell>
> <TableCell>
> <ReportItems>
> <Textbox Name="textbox4">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Right</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> <FontWeight>700</FontWeight>
> </Style>
> <ZIndex>2</ZIndex>
> <rd:DefaultName>textbox4</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>Order ID</Value>
> </Textbox>
> </ReportItems>
> </TableCell>
> </TableCells>
> </TableRow>
> </TableRows>
> <RepeatOnNewPage>true</RepeatOnNewPage>
> </Header>
> <Details>
> <TableRows>
> <TableRow>
> <Height>0.25in</Height>
> <TableCells>
> <TableCell>
> <ReportItems>
> <Textbox Name="CustomerID_1">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> </Style>
> <ZIndex>1</ZIndex>
> <rd:DefaultName>CustomerID_1</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=Fields!CustomerID.Value</Value>
> </Textbox>
> </ReportItems>
> </TableCell>
> <TableCell>
> <ReportItems>
> <Textbox Name="OrderID">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Right</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> </Style>
> <rd:DefaultName>OrderID</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=Fields!OrderID.Value</Value>
> </Textbox>
> </ReportItems>
> </TableCell>
> </TableCells>
> </TableRow>
> </TableRows>
> <Sorting>
> <SortBy>
> <SortExpression>=Fields!CustomerID.Value</SortExpression>
> <Direction>Ascending</Direction>
> </SortBy>
> <SortBy>
> <SortExpression>=Fields!OrderID.Value</SortExpression>
> <Direction>Ascending</Direction>
> </SortBy>
> </Sorting>
> </Details>
> <DataSetName>DataSet1</DataSetName>
> <Width>1.875in</Width>
> <TableColumns>
> <TableColumn>
> <Width>1in</Width>
> </TableColumn>
> <TableColumn>
> <Width>0.875in</Width>
> </TableColumn>
> </TableColumns>
> </Table>
> <Matrix Name="matrix1">
> <Corner>
> <ReportItems>
> <Textbox Name="textbox1">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Left</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> <FontWeight>700</FontWeight>
> </Style>
> <ZIndex>4</ZIndex>
> <rd:DefaultName>textbox1</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>CustomerID, OrderID</Value>
> </Textbox>
> </ReportItems>
> </Corner>
> <Height>0.5in</Height>
> <Style />
> <MatrixRows>
> <MatrixRow>
> <MatrixCells>
> <MatrixCell>
> <ReportItems>
> <Textbox Name="CompanyName">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Left</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> </Style>
> <rd:DefaultName>CompanyName</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=First(Fields!CompanyName.Value)</Value>
> </Textbox>
> </ReportItems>
> </MatrixCell>
> </MatrixCells>
> <Height>0.25in</Height>
> </MatrixRow>
> </MatrixRows>
> <MatrixColumns>
> <MatrixColumn>
> <Width>1.375in</Width>
> </MatrixColumn>
> </MatrixColumns>
> <DataSetName>DataSet1</DataSetName>
> <ColumnGroupings>
> <ColumnGrouping>
> <DynamicColumns>
> <Grouping Name="matrix1_CompanyName">
> <GroupExpressions>
> <GroupExpression>=Fields!CompanyName.Value</GroupExpression>
> </GroupExpressions>
> </Grouping>
> <ReportItems>
> <Textbox Name="CompanyName_1">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Left</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> <FontWeight>700</FontWeight>
> </Style>
> <ZIndex>3</ZIndex>
> <rd:DefaultName>CompanyName_1</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=Fields!CompanyName.Value</Value>
> </Textbox>
> </ReportItems>
> </DynamicColumns>
> <Height>0.25in</Height>
> </ColumnGrouping>
> </ColumnGroupings>
> <Width>3.25in</Width>
> <Left>2in</Left>
> <RowGroupings>
> <RowGrouping>
> <DynamicRows>
> <Grouping Name="matrix1_CustomerID">
> <GroupExpressions>
> <GroupExpression>=Fields!CustomerID.Value</GroupExpression>
> </GroupExpressions>
> </Grouping>
> <Sorting>
> <SortBy>
>
<SortExpression>=Fields!CustomerID.Value</SortExpression>
> <Direction>Ascending</Direction>
> </SortBy>
> </Sorting>
> <ReportItems>
> <Textbox Name="CustomerID">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Left</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> </Style>
> <ZIndex>2</ZIndex>
> <rd:DefaultName>CustomerID</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=Fields!CustomerID.Value</Value>
> </Textbox>
> </ReportItems>
> </DynamicRows>
> <Width>0.875in</Width>
> </RowGrouping>
> <RowGrouping>
> <DynamicRows>
> <Grouping Name="matrix1_OrderID">
> <GroupExpressions>
> <GroupExpression>=Fields!OrderID.Value</GroupExpression>
> </GroupExpressions>
> </Grouping>
> <Sorting>
> <SortBy>
> <SortExpression>=Fields!OrderID.Value</SortExpression>
> <Direction>Ascending</Direction>
> </SortBy>
> </Sorting>
> <ReportItems>
> <Textbox Name="textbox2">
> <Style>
> <PaddingLeft>2pt</PaddingLeft>
> <TextAlign>Left</TextAlign>
> <PaddingBottom>2pt</PaddingBottom>
> <PaddingTop>2pt</PaddingTop>
> <PaddingRight>2pt</PaddingRight>
> </Style>
> <ZIndex>1</ZIndex>
> <rd:DefaultName>textbox2</rd:DefaultName>
> <CanGrow>true</CanGrow>
> <Value>=Fields!OrderID.Value</Value>
> </Textbox>
> </ReportItems>
> </DynamicRows>
> <Width>1in</Width>
> </RowGrouping>
> </RowGroupings>
> </Matrix>
> </ReportItems>
> <Style />
> <Height>3in</Height>
> </Body>
> <TopMargin>0.25in</TopMargin>
> <DataSources>
> <DataSource Name="Northwind">
> <rd:DataSourceID>d83220b8-b683-4ff8-970d-134479e0e9d3</rd:DataSourceID>
> <ConnectionProperties>
> <DataProvider>SQL</DataProvider>
> <ConnectString>data source=localhost;initial
> catalog=Northwind</ConnectString>
> <IntegratedSecurity>true</IntegratedSecurity>
> </ConnectionProperties>
> </DataSource>
> </DataSources>
> <Width>8in</Width>
> <DataSets>
> <DataSet Name="DataSet1">
> <Fields>
> <Field Name="OrderID">
> <DataField>OrderID</DataField>
> <rd:TypeName>System.Int32</rd:TypeName>
> </Field>
> <Field Name="CustomerID">
> <DataField>CustomerID</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> <Field Name="CompanyName">
> <DataField>CompanyName</DataField>
> <rd:TypeName>System.String</rd:TypeName>
> </Field>
> </Fields>
> <Query>
> <DataSourceName>Northwind</DataSourceName>
> <CommandText>SELECT
> OrderID,
> Orders.CustomerID,
> Shippers.CompanyName FROM Orders
> INNER JOIN Customers ON Customers.CustomerID = Orders.CustomerID
> INNER JOIN Shippers ON Shippers.ShipperID = Orders.ShipVia</CommandText>
> <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
> </Query>
> </DataSet>
> </DataSets>
> <LeftMargin>0.25in</LeftMargin>
> <rd:SnapToGrid>true</rd:SnapToGrid>
> <rd:DrawGrid>true</rd:DrawGrid>
> <rd:ReportID>82805f4c-8060-4d41-a1d0-bba1d089578f</rd:ReportID>
> <BottomMargin>0.25in</BottomMargin>
> <Language>en-US</Language>
> </Report>
>

Sunday, March 11, 2012

Bug in UPDATE statement and 1 : n cardinality ?

The problem is in one-to-many cardinality and UPDATE statement :
( SQL server 2005 developer edition )

create table #table1( id int, firstCol int)
insert #table1 values ( 1,0)
insert #table1 values ( 2,0)
go

create table #table2( id int, secondCol int)
insert #table2 values ( 1,10)
insert #table2 values ( 1,20)
insert #table2 values ( 1,30)
insert #table2 values ( 3,100)
go

--

1. shape UPDATE

update #table1 set firstCol = firstCol +( select secondCol from #table2
where #table1.id = #table2.id )

return error message :

Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.

2. shape UPDATE

update r set firstCol = firstCol + s.secondCol
from #table1 r
join ( select id,secondCol from #table2 ) s
on r.id = s.id

return message : (1 row(s) affected)
and #table1 is updated only one of row ( generally random ) from #table2 for ID = 1

select * from #table1

id firstCol
-- --
1 10
2 0

3. shape UPDATE

update #table1 set firstCol = firstCol + secondCol
from #table2 where #table1.id = #table2.id

return message : (1 row(s) affected)
and #table1 is updated only one of row ( generally random ) from #table2 for ID = 1

--

Is it normal ? I expected error message or summary value for ID = 1 from #table2 .

The behavior of SQL Server's proprietary UPDATE .. FROM statement

is undefined in this situation, and this is documented in Books

Online:

UPDATE (Transact-SQL)

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/40e63302-0c68-4593-af3e-6d190181fee7.htm

The results of an UPDATE statement are undefined if the statement

includes a FROM clause that is not specified in such a way that

only one value is available for each column occurrence that is

updated, that is if the UPDATE statement is not deterministic.

For example, in the UPDATE statement in the following script,

both rows in Table1 meet the qualifications of the FROM clause

in the UPDATE statement; but it is undefined which row from

Table1 is used to update the row in Table2.

Similar language appears in the article

Changing Data by Using the FROM Clause

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/f4b7f060-f21b-4117-93cb-c7a7cc75569c.htm

Steve Kass

Drew University

http://www.stevekass.com

Jiri Lichtenberg@.discussions.microsoft.com wrote:

>

>

> The problem is in one-to-many cardinality and UPDATE statement :

> ( SQL server 2005 developer edition )

>

> create table #table1( id int, firstCol int)

> insert #table1 values ( 1,0)

> insert #table1 values ( 2,0)

> go

>

> create table #table2( id int, secondCol int)

> insert #table2 values ( 1,10)

> insert #table2 values ( 1,20)

> insert #table2 values ( 1,30)

> insert #table2 values ( 3,100)

> go

>

>

> --

>

> 1. shape UPDATE

>

> update #table1 set firstCol = firstCol +( select secondCol from #table2

> where #table1.id = #table2.id )

>

> return error message :

>

> Msg 512, Level 16, State 1, Line 1

> Subquery returned more than 1 value. This is not permitted when the

> subquery follows =, !=, <, <= , >, >= or when the subquery is used as an

> expression.

> The statement has been terminated.

>

> 2. shape UPDATE

>

> update r set firstCol = firstCol + s.secondCol

> from #table1 r

> join ( select id,secondCol from #table2 ) s

> on r.id = s.id

>

> return message : (1 row(s) affected)

> and #table1 is updated only one of row ( generally random ) from #table2

> for ID = 1

>

> select * from #table1

>

> id firstCol

> -- --

> 1 10

> 2 0

>

> 3. shape UPDATE

>

> update #table1 set firstCol = firstCol + secondCol

> from #table2 where #table1.id = #table2.id

>

> return message : (1 row(s) affected)

> and #table1 is updated only one of row ( generally random ) from #table2

> for ID = 1

>

>

> --

>

> Is it normal ? I expected error message or summary value for ID = 1

> from #table2 .

>

>

>

>

Bug in SQL Server 2000 sp3?

Hi
I have a table defined as
create table Project
(
Project nvarchar(20) collate database_default not null constraint
DF_Project_Project default '',
/* some other irrelevant fields */
CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
)
If I insert a long numeric value into Project (3123456789), I get some
troubles:
insert Project (Project) values ('3123456789')
If i execute the statement
select Project from Project
in Query Analyzer, I get the expected result (the record shown in the result
grid)
If i execute the statement
select * from Project
I get the following error (and no record shown in the result grid)
Server: Msg 248, Level 16, State 1, Line 1
The conversion of the nvarchar value '3123456789' overflowed an int column.
Maximum integer value exceeded.
Why??
My SQL Server version is (according to Select @.@.Version)
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
IMO, using Select * should be functionally equal to a Select statement
listing all fields in the table, but it is not.
Best regards,
Benny Tordrup
Benny Tordrup wrote:
> Hi
> I have a table defined as
> create table Project
> (
> Project nvarchar(20) collate database_default not null constraint
> DF_Project_Project default '',
> /* some other irrelevant fields */
> CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
> )
> If I insert a long numeric value into Project (3123456789), I get some
> troubles:
> insert Project (Project) values ('3123456789')
>
> If i execute the statement
> select Project from Project
> in Query Analyzer, I get the expected result (the record shown in the
> result grid)
> If i execute the statement
> select * from Project
> I get the following error (and no record shown in the result grid)
> Server: Msg 248, Level 16, State 1, Line 1
> The conversion of the nvarchar value '3123456789' overflowed an int
> column. Maximum integer value exceeded.
>
> Why??
> My SQL Server version is (according to Select @.@.Version)
>
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> IMO, using Select * should be functionally equal to a Select statement
> listing all fields in the table, but it is not.
> Best regards,
> Benny Tordrup
I went ahead and recreated your table here and don't get any error. Not
sure what the problem is.
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 1)
David G.
|||You can get the error you mention if you have a computed column in the table
that uses the project column in its expression.
Jacco Schalkwijk
SQL Server MVP
"Benny Tordrup" <nospam dot bt at fk-data dot dk> wrote in message
news:%23WshbbwlEHA.3520@.TK2MSFTNGP11.phx.gbl...
> Hi
> I have a table defined as
> create table Project
> (
> Project nvarchar(20) collate database_default not null constraint
> DF_Project_Project default '',
> /* some other irrelevant fields */
> CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
> )
> If I insert a long numeric value into Project (3123456789), I get some
> troubles:
> insert Project (Project) values ('3123456789')
>
> If i execute the statement
> select Project from Project
> in Query Analyzer, I get the expected result (the record shown in the
> result
> grid)
> If i execute the statement
> select * from Project
> I get the following error (and no record shown in the result grid)
> Server: Msg 248, Level 16, State 1, Line 1
> The conversion of the nvarchar value '3123456789' overflowed an int
> column.
> Maximum integer value exceeded.
>
> Why??
> My SQL Server version is (according to Select @.@.Version)
>
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> IMO, using Select * should be functionally equal to a Select statement
> listing all fields in the table, but it is not.
> Best regards,
> Benny Tordrup
>
|||Jacco,
It was exactly the problem.
I had a computed column defined as
Cast(Case when IsNumeric(Project)=0 then 0 else Project end as
decimal(20,0))
Changing the definition to
Cast(Case when IsNumeric(Project)=0 then '0' else Project end as
decimal(20,0))
solved my problem
Thanks
Benny
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid > skrev
i en meddelelse news:eGgnRixlEHA.596@.tk2msftngp13.phx.gbl...
> You can get the error you mention if you have a computed column in the
table
> that uses the project column in its expression.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Benny Tordrup" <nospam dot bt at fk-data dot dk> wrote in message
> news:%23WshbbwlEHA.3520@.TK2MSFTNGP11.phx.gbl...
>

Bug in SQL Server 2000 sp3?

Hi
I have a table defined as
create table Project
(
Project nvarchar(20) collate database_default not null constraint
DF_Project_Project default '',
/* some other irrelevant fields */
CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
)
If I insert a long numeric value into Project (3123456789), I get some
troubles:
insert Project (Project) values ('3123456789')
If i execute the statement
select Project from Project
in Query Analyzer, I get the expected result (the record shown in the result
grid)
If i execute the statement
select * from Project
I get the following error (and no record shown in the result grid)
Server: Msg 248, Level 16, State 1, Line 1
The conversion of the nvarchar value '3123456789' overflowed an int column.
Maximum integer value exceeded.
Why''
My SQL Server version is (according to Select @.@.Version)
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
IMO, using Select * should be functionally equal to a Select statement
listing all fields in the table, but it is not.
Best regards,
Benny TordrupBenny Tordrup wrote:
> Hi
> I have a table defined as
> create table Project
> (
> Project nvarchar(20) collate database_default not null constraint
> DF_Project_Project default '',
> /* some other irrelevant fields */
> CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
> )
> If I insert a long numeric value into Project (3123456789), I get some
> troubles:
> insert Project (Project) values ('3123456789')
>
> If i execute the statement
> select Project from Project
> in Query Analyzer, I get the expected result (the record shown in the
> result grid)
> If i execute the statement
> select * from Project
> I get the following error (and no record shown in the result grid)
> Server: Msg 248, Level 16, State 1, Line 1
> The conversion of the nvarchar value '3123456789' overflowed an int
> column. Maximum integer value exceeded.
>
> Why''
> My SQL Server version is (according to Select @.@.Version)
>
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> IMO, using Select * should be functionally equal to a Select statement
> listing all fields in the table, but it is not.
> Best regards,
> Benny Tordrup
I went ahead and recreated your table here and don't get any error. Not
sure what the problem is.
Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
Dec 17 2002 14:22:05
Copyright (c) 1988-2003 Microsoft Corporation
Personal Edition on Windows NT 5.1 (Build 2600: Service Pack 1)
--
David G.|||You can get the error you mention if you have a computed column in the table
that uses the project column in its expression.
--
Jacco Schalkwijk
SQL Server MVP
"Benny Tordrup" <nospam dot bt at fk-data dot dk> wrote in message
news:%23WshbbwlEHA.3520@.TK2MSFTNGP11.phx.gbl...
> Hi
> I have a table defined as
> create table Project
> (
> Project nvarchar(20) collate database_default not null constraint
> DF_Project_Project default '',
> /* some other irrelevant fields */
> CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
> )
> If I insert a long numeric value into Project (3123456789), I get some
> troubles:
> insert Project (Project) values ('3123456789')
>
> If i execute the statement
> select Project from Project
> in Query Analyzer, I get the expected result (the record shown in the
> result
> grid)
> If i execute the statement
> select * from Project
> I get the following error (and no record shown in the result grid)
> Server: Msg 248, Level 16, State 1, Line 1
> The conversion of the nvarchar value '3123456789' overflowed an int
> column.
> Maximum integer value exceeded.
>
> Why''
> My SQL Server version is (according to Select @.@.Version)
>
> Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> Dec 17 2002 14:22:05
> Copyright (c) 1988-2003 Microsoft Corporation
> Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> IMO, using Select * should be functionally equal to a Select statement
> listing all fields in the table, but it is not.
> Best regards,
> Benny Tordrup
>|||Jacco,
It was exactly the problem.
I had a computed column defined as
Cast(Case when IsNumeric(Project)=0 then 0 else Project end as
decimal(20,0))
Changing the definition to
Cast(Case when IsNumeric(Project)=0 then '0' else Project end as
decimal(20,0))
solved my problem
Thanks
Benny
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> skrev
i en meddelelse news:eGgnRixlEHA.596@.tk2msftngp13.phx.gbl...
> You can get the error you mention if you have a computed column in the
table
> that uses the project column in its expression.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Benny Tordrup" <nospam dot bt at fk-data dot dk> wrote in message
> news:%23WshbbwlEHA.3520@.TK2MSFTNGP11.phx.gbl...
> > Hi
> >
> > I have a table defined as
> >
> > create table Project
> > (
> > Project nvarchar(20) collate database_default not null constraint
> > DF_Project_Project default '',
> > /* some other irrelevant fields */
> >
> > CONSTRAINT [Project_PrimaryKey] PRIMARY KEY CLUSTERED ([Project])
> > )
> >
> > If I insert a long numeric value into Project (3123456789), I get some
> > troubles:
> >
> > insert Project (Project) values ('3123456789')
> >
> >
> > If i execute the statement
> >
> > select Project from Project
> >
> > in Query Analyzer, I get the expected result (the record shown in the
> > result
> > grid)
> >
> > If i execute the statement
> >
> > select * from Project
> >
> > I get the following error (and no record shown in the result grid)
> >
> > Server: Msg 248, Level 16, State 1, Line 1
> > The conversion of the nvarchar value '3123456789' overflowed an int
> > column.
> > Maximum integer value exceeded.
> >
> >
> > Why''
> >
> > My SQL Server version is (according to Select @.@.Version)
> >
> >
> > Microsoft SQL Server 2000 - 8.00.760 (Intel X86)
> > Dec 17 2002 14:22:05
> > Copyright (c) 1988-2003 Microsoft Corporation
> > Standard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)
> >
> > IMO, using Select * should be functionally equal to a Select statement
> > listing all fields in the table, but it is not.
> >
> > Best regards,
> >
> > Benny Tordrup
> >
> >
>

Thursday, March 8, 2012

Bug in INFORMATION_SCHEMA?

We just confirmed that if you change the length of a varchar in a table,
INFORMATION_SCHEMA.CHARACTER_MAXIMUM_LENGTH does not automatically update
for views that use that varchar. You have to drop and recreate the view for
the update to occur. This is a bug in my opinion especially since MS insits
you use the views and not the underlying sys tables. We use a C# class
generator that creates code based on those values and ran into this problem.
Anyone else noticed this?
</joel>That's not a bug -- the problem is that altering a table does not alter the
view that references the table. For instance, you can alter a table and
drop a column, and the view will not be affected -- you'll find out next
time you query it, though!
One way to keep problems like this from happening is to use the WITH
SCHEMABINDING option. This will disallow changes to the base table unless
you drop the view -- meaning that the view will have to be recreated after
you alter the table, and the INFORMATION_SCHEMA will therefore get updated.
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Joel" <joelycat@.hotmail.com> wrote in message
news:%23uM$EeWKFHA.4092@.tk2msftngp13.phx.gbl...
> We just confirmed that if you change the length of a varchar in a table,
> INFORMATION_SCHEMA.CHARACTER_MAXIMUM_LENGTH does not automatically update
> for views that use that varchar. You have to drop and recreate the view
for
> the update to occur. This is a bug in my opinion especially since MS
insits
> you use the views and not the underlying sys tables. We use a C# class
> generator that creates code based on those values and ran into this
problem.
> Anyone else noticed this?
> </joel>
>|||When you change an underlying table, view metadata (in system tables) is not
automatically updated. You need to execute sp_refreshview or ALTER or
DROP/CREATE the view.
Note that this affects not only the data returned by the INFORMATION_SCHEMA
views but also the view itself. You will get old column definitions until
the metadata is refreshed. Illustrative script:
CREATE TABLE Table1(Col1 varchar(10))
GO
CREATE VIEW View1 AS SELECT Col1 FROM Table1
GO
EXEC sp_help 'View1' -- length 10
ALTER TABLE Table1 ALTER COLUMN Col1 varchar(20)
EXEC sp_help 'View1' -- length 10
EXEC sp_refreshview 'View1'
EXEC sp_help 'View1' -- length 20
GO
We follow a standard practice of executing sp_refreshview against all views
following schema changes.
Hope this helps.
Dan Guzman
SQL Server MVP
"Joel" <joelycat@.hotmail.com> wrote in message
news:%23uM$EeWKFHA.4092@.tk2msftngp13.phx.gbl...
> We just confirmed that if you change the length of a varchar in a table,
> INFORMATION_SCHEMA.CHARACTER_MAXIMUM_LENGTH does not automatically update
> for views that use that varchar. You have to drop and recreate the view
> for the update to occur. This is a bug in my opinion especially since MS
> insits you use the views and not the underlying sys tables. We use a C#
> class generator that creates code based on those values and ran into this
> problem.
> Anyone else noticed this?
> </joel>
>|||That's not a bug in the INFORMATION_SCHEMA really. The metadata about the
columns that are in a view are stored with the view definition and are not
automatically updated when you change the underlying table(s). (This is a
one of the reasons why it is no good idea to use SELECT * in a view).
You don't have to drop and recreate the view for the metadata to be updated
though, you can achieve that with:
EXEC sp_refreshview '<view_name>'
Jacco Schalkwijk
SQL Server MVP
"Joel" <joelycat@.hotmail.com> wrote in message
news:%23uM$EeWKFHA.4092@.tk2msftngp13.phx.gbl...
> We just confirmed that if you change the length of a varchar in a table,
> INFORMATION_SCHEMA.CHARACTER_MAXIMUM_LENGTH does not automatically update
> for views that use that varchar. You have to drop and recreate the view
> for the update to occur. This is a bug in my opinion especially since MS
> insits you use the views and not the underlying sys tables. We use a C#
> class generator that creates code based on those values and ran into this
> problem.
> Anyone else noticed this?
> </joel>
>|||> for views that use that varchar. You have to drop and recreate the view
for
> the update to occur.
Are you changing the definition of the view, or the underlying table? If
you create your view with SCHEMABINDING, you won't be able to change the
underlying table, and this won't be an issue. Otherwise, plan to run
sp_refreshview on all views that reference the table in order to update the
metadata (this applies both to
INFORMATION_SCHEMA.COLUMNS.CHARACTER_MAXIMUM_LENGTH and syscolumns.length).
Books Online documents this quite well, in fact:
"Refreshes the metadata for the specified view. Persistent metadata for a
view can become outdated because of changes to the underlying objects upon
which the view depends."
While it would be a nice enhancement for the metadata to truly reflect the
current state, I don't think Microsoft will consider it a bug because the
behavior is documented. I also think it would be quite expensive for SQL
Server to watch for ALTER TABLE events and then go and parse all the views
that reference it and make sure their metadata is updated also...
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.|||Wow, DBAs! :-)
I can certainly see in the case of dropping a column that SqlServer wouldn't
parse a View and try to figure out the program's intent, but a column length
is a column length.
If it walks like a bug...
</joel>
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:uWIIeoWKFHA.4028@.tk2msftngp13.phx.gbl...
> That's not a bug -- the problem is that altering a table does not alter
> the
> view that references the table. For instance, you can alter a table and
> drop a column, and the view will not be affected -- you'll find out next
> time you query it, though!
> One way to keep problems like this from happening is to use the WITH
> SCHEMABINDING option. This will disallow changes to the base table unless
> you drop the view -- meaning that the view will have to be recreated after
> you alter the table, and the INFORMATION_SCHEMA will therefore get
> updated.
>
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Joel" <joelycat@.hotmail.com> wrote in message
> news:%23uM$EeWKFHA.4092@.tk2msftngp13.phx.gbl...
> for
> insits
> problem.
>|||You found that response "Angry".
You haven't been in this newsgroup very long, have you?
Don't take your frustration out on people answering your questions just
because you don't like the answer.
If you don't like how SQL server handles this send your request to
Microsoft.
"Joel" <joelycat@.hotmail.com> wrote in message
news:%23GqmeCXKFHA.2800@.TK2MSFTNGP10.phx.gbl...
> Wow, DBAs! :-)
> I can certainly see in the case of dropping a column that SqlServer
> wouldn't parse a View and try to figure out the program's intent, but a
> column length is a column length.
> If it walks like a bug...
> </joel>
> "Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
> news:uWIIeoWKFHA.4028@.tk2msftngp13.phx.gbl...
>|||> Wow, DBAs! :-)
Who's ?

> If it walks like a bug...
Again, a bug to you is not a bug to everybody. This behavior is well-known
and well-documented.|||"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:Oqfel%23XKFHA.3184@.TK2MSFTNGP09.phx.gbl...
> Who's ?
I'm that someone would imply that I am .
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--

Wednesday, March 7, 2012

Bug in CASE statement?

(SQL Server 2000, SP3a)
Hello all!
I'm trying to "seed" some random data in a table, and am having some trouble with the CASE
statement that I don't fully understand.
Consider the following:
select id,
[Rating] = case (abs(convert(int, convert(varbinary(4), newid())) % 5))
when 0 then NULL
when 1 then 'Poor'
when 2 then 'Fair'
when 3 then 'Good'
when 4 then 'Excellent'
else '?'
end
from sysobjects
I would expect this to return values in the range of 0-4, which would map to the various
strings that you see. However, I keep getting a high incidence of '?' strings returned.
When I use the exact same expression without the CASE statement:
select distinct Rating
from (
select Rating = abs(convert(int, convert(varbinary(4), newid())) % 5)
from sysobjects
) as q
I show that, indeed, the only values that are returned are 0-4.
This sure *seems* like a bug to me, but I suspect the problem lies in my understanding of
the CASE statement.
Any help would be much appreciated! :-)
John PetersonHi John
The only problem you are having with CASE is your terminology. CASE is an
expression, not a statement. But since you are using it as an expression,
within the SELECT statement, you do seem to understand it.
This is very strange behavior indeed. I think the problem is with NEWID().
You can establish that your understanding of the CASE expression by changing
NEWID() to something else, like id from the sysobjects table (and I am also
returning the value computed by the case expression for comparison
purposes):
select id,abs(convert(int, convert(varbinary(4), id)) % 5),
[Rating] = case (abs(convert(int, convert(varbinary(4), id)) % 5))
when 0 then NULL
when 1 then 'Poor'
when 2 then 'Fair'
when 3 then 'Good'
when 4 then 'Excellent'
else '?'
end
from sysobjects
The above seems to work as expected.
My guess is that NEWID() is being regenerated for EVERY comparison, so the
value is always changing. So your expression abs(convert(int,
convert(varbinary(4), id)) % 5) is evaluated and compared to 0, and if so,
NULL is returned, otherwise the expression is evaluted AGAIN (with a new
NEWID() ) and that is compared to 1, and if that one wasn't equal to one,
another NEWID() expression is compared to 2, etc. So it's hardly surprising
that few of the expressions will match the constant you're comparing too
(although a few will) and many will have no match and fall through to '?'
Why don't you tell us exactly what you're trying to do, and someone may have
another suggestion for you.
In the meantime, I'll try to find out what's happening with NEWID() here.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"John Peterson" <j0hnp@.comcast.net> wrote in message
news:eaQO0ZzkDHA.976@.tk2msftngp13.phx.gbl...
> (SQL Server 2000, SP3a)
> Hello all!
> I'm trying to "seed" some random data in a table, and am having some
trouble with the CASE
> statement that I don't fully understand.
> Consider the following:
>
> select id,
> [Rating] = case (abs(convert(int, convert(varbinary(4), newid())) %
5))
> when 0 then NULL
> when 1 then 'Poor'
> when 2 then 'Fair'
> when 3 then 'Good'
> when 4 then 'Excellent'
> else '?'
> end
> from sysobjects
>
> I would expect this to return values in the range of 0-4, which would map
to the various
> strings that you see. However, I keep getting a high incidence of '?'
strings returned.
>
> When I use the exact same expression without the CASE statement:
>
> select distinct Rating
> from (
> select Rating = abs(convert(int, convert(varbinary(4), newid())) %
5)
> from sysobjects
> ) as q
>
> I show that, indeed, the only values that are returned are 0-4.
> This sure *seems* like a bug to me, but I suspect the problem lies in my
understanding of
> the CASE statement.
> Any help would be much appreciated! :-)
> John Peterson
>|||Hello, Kalen! Please see inline:
"Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
news:ubXkerzkDHA.3312@.tk2msftngp13.phx.gbl...
> Hi John
> The only problem you are having with CASE is your terminology. CASE is an
> expression, not a statement. But since you are using it as an expression,
> within the SELECT statement, you do seem to understand it.
Thanks -- I always want to use the correct nomenclature. I bet if I would have looked in
BOL, I might have used the right term. :-)
> This is very strange behavior indeed. I think the problem is with NEWID().
> You can establish that your understanding of the CASE expression by changing
> NEWID() to something else, like id from the sysobjects table (and I am also
> returning the value computed by the case expression for comparison
> purposes):
> select id,abs(convert(int, convert(varbinary(4), id)) % 5),
> [Rating] = case (abs(convert(int, convert(varbinary(4), id)) % 5))
> when 0 then NULL
> when 1 then 'Poor'
> when 2 then 'Fair'
> when 3 then 'Good'
> when 4 then 'Excellent'
> else '?'
> end
> from sysobjects
> The above seems to work as expected.
Yeah, that's exactly what I wound up doing in my table, since the IDs were GUIDs, I didn't
necessarily need to use newid().
> My guess is that NEWID() is being regenerated for EVERY comparison, so the
> value is always changing. So your expression abs(convert(int,
> convert(varbinary(4), id)) % 5) is evaluated and compared to 0, and if so,
> NULL is returned, otherwise the expression is evaluted AGAIN (with a new
> NEWID() ) and that is compared to 1, and if that one wasn't equal to one,
> another NEWID() expression is compared to 2, etc. So it's hardly surprising
> that few of the expressions will match the constant you're comparing too
> (although a few will) and many will have no match and fall through to '?'
Oh, interesting! I guess that sort of makes sense if the "internals" of the execution are
always re-evaluating NEWID() instead of just having one persistent value.
> Why don't you tell us exactly what you're trying to do, and someone may have
> another suggestion for you.
> In the meantime, I'll try to find out what's happening with NEWID() here.
All I really wanted to do was generate some random data -- and I tried using the RAND()
function, but it would only evaluate RAND() *once* for every row in the result set (just
like GETDATE() does, I believe); as such, every value was the same. So, I switched to use
NEWID(), since that appears to generate a new value for each row in the result set.
At this point, I was able to use a variant of your suggestion (to use a static value
instead of NEWID()) to generate my random data. But, I thought it would be worth posting
this issue to try and find out more about it. :-)
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "John Peterson" <j0hnp@.comcast.net> wrote in message
> news:eaQO0ZzkDHA.976@.tk2msftngp13.phx.gbl...
> > (SQL Server 2000, SP3a)
> >
> > Hello all!
> >
> > I'm trying to "seed" some random data in a table, and am having some
> trouble with the CASE
> > statement that I don't fully understand.
> >
> > Consider the following:
> >
> >
> > select id,
> > [Rating] = case (abs(convert(int, convert(varbinary(4), newid())) %
> 5))
> > when 0 then NULL
> > when 1 then 'Poor'
> > when 2 then 'Fair'
> > when 3 then 'Good'
> > when 4 then 'Excellent'
> > else '?'
> > end
> > from sysobjects
> >
> >
> > I would expect this to return values in the range of 0-4, which would map
> to the various
> > strings that you see. However, I keep getting a high incidence of '?'
> strings returned.
> >
> >
> > When I use the exact same expression without the CASE statement:
> >
> >
> > select distinct Rating
> > from (
> > select Rating = abs(convert(int, convert(varbinary(4), newid())) %
> 5)
> > from sysobjects
> > ) as q
> >
> >
> > I show that, indeed, the only values that are returned are 0-4.
> >
> > This sure *seems* like a bug to me, but I suspect the problem lies in my
> understanding of
> > the CASE statement.
> >
> > Any help would be much appreciated! :-)
> >
> > John Peterson
> >
> >
>|||Yes, this is an useful distinction between RAND() and NEWID(). I knew
NEWID() regenerated for each row, but it sure seems strange that it would
reevaluate for every comparison within a CASE.
But it's probably good to know this!
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"John Peterson" <j0hnp@.comcast.net> wrote in message
news:uBnY#xzkDHA.2312@.TK2MSFTNGP12.phx.gbl...
> Hello, Kalen! Please see inline:
> "Kalen Delaney" <replies@.public_newsgroups.com> wrote in message
> news:ubXkerzkDHA.3312@.tk2msftngp13.phx.gbl...
> > Hi John
> > The only problem you are having with CASE is your terminology. CASE is
an
> > expression, not a statement. But since you are using it as an
expression,
> > within the SELECT statement, you do seem to understand it.
> Thanks -- I always want to use the correct nomenclature. I bet if I would
have looked in
> BOL, I might have used the right term. :-)
>
> > This is very strange behavior indeed. I think the problem is with
NEWID().
> > You can establish that your understanding of the CASE expression by
changing
> > NEWID() to something else, like id from the sysobjects table (and I am
also
> > returning the value computed by the case expression for comparison
> > purposes):
> >
> > select id,abs(convert(int, convert(varbinary(4), id)) % 5),
> > [Rating] = case (abs(convert(int, convert(varbinary(4), id)) %
5))
> > when 0 then NULL
> > when 1 then 'Poor'
> > when 2 then 'Fair'
> > when 3 then 'Good'
> > when 4 then 'Excellent'
> > else '?'
> > end
> > from sysobjects
> >
> > The above seems to work as expected.
> Yeah, that's exactly what I wound up doing in my table, since the IDs were
GUIDs, I didn't
> necessarily need to use newid().
>
> > My guess is that NEWID() is being regenerated for EVERY comparison, so
the
> > value is always changing. So your expression abs(convert(int,
> > convert(varbinary(4), id)) % 5) is evaluated and compared to 0, and if
so,
> > NULL is returned, otherwise the expression is evaluted AGAIN (with a new
> > NEWID() ) and that is compared to 1, and if that one wasn't equal to
one,
> > another NEWID() expression is compared to 2, etc. So it's hardly
surprising
> > that few of the expressions will match the constant you're comparing too
> > (although a few will) and many will have no match and fall through to
'?'
> Oh, interesting! I guess that sort of makes sense if the "internals" of
the execution are
> always re-evaluating NEWID() instead of just having one persistent value.
>
> > Why don't you tell us exactly what you're trying to do, and someone may
have
> > another suggestion for you.
> > In the meantime, I'll try to find out what's happening with NEWID()
here.
> All I really wanted to do was generate some random data -- and I tried
using the RAND()
> function, but it would only evaluate RAND() *once* for every row in the
result set (just
> like GETDATE() does, I believe); as such, every value was the same. So, I
switched to use
> NEWID(), since that appears to generate a new value for each row in the
result set.
> At this point, I was able to use a variant of your suggestion (to use a
static value
> instead of NEWID()) to generate my random data. But, I thought it would
be worth posting
> this issue to try and find out more about it. :-)
>
> > --
> > HTH
> > --
> > Kalen Delaney
> > SQL Server MVP
> > www.SolidQualityLearning.com
> >
> >
> > "John Peterson" <j0hnp@.comcast.net> wrote in message
> > news:eaQO0ZzkDHA.976@.tk2msftngp13.phx.gbl...
> > > (SQL Server 2000, SP3a)
> > >
> > > Hello all!
> > >
> > > I'm trying to "seed" some random data in a table, and am having some
> > trouble with the CASE
> > > statement that I don't fully understand.
> > >
> > > Consider the following:
> > >
> > >
> > > select id,
> > > [Rating] = case (abs(convert(int, convert(varbinary(4),
newid())) %
> > 5))
> > > when 0 then NULL
> > > when 1 then 'Poor'
> > > when 2 then 'Fair'
> > > when 3 then 'Good'
> > > when 4 then 'Excellent'
> > > else '?'
> > > end
> > > from sysobjects
> > >
> > >
> > > I would expect this to return values in the range of 0-4, which would
map
> > to the various
> > > strings that you see. However, I keep getting a high incidence of '?'
> > strings returned.
> > >
> > >
> > > When I use the exact same expression without the CASE statement:
> > >
> > >
> > > select distinct Rating
> > > from (
> > > select Rating = abs(convert(int, convert(varbinary(4),
newid())) %
> > 5)
> > > from sysobjects
> > > ) as q
> > >
> > >
> > > I show that, indeed, the only values that are returned are 0-4.
> > >
> > > This sure *seems* like a bug to me, but I suspect the problem lies in
my
> > understanding of
> > > the CASE statement.
> > >
> > > Any help would be much appreciated! :-)
> > >
> > > John Peterson
> > >
> > >
> >
> >
>|||Hello
> select id,
> [Rating] = case (abs(convert(int, convert(varbinary(4), newid())) %
5))
> when 0 then NULL
> when 1 then 'Poor'
> when 2 then 'Fair'
> when 3 then 'Good'
> when 4 then 'Excellent'
> else '?'
> end
> from sysobjects
>
> I would expect this to return values in the range of 0-4, which would map
to the various
> strings that you see. However, I keep getting a high incidence of '?'
strings returned.
What version of SQL server are you using?
I've tested your query on my MSSQL 2000 EE + SP3 and it works fine.
Number of '?' is near the number of other variants.
Serge Shakhov|||That's just it -- there should be *no* '?' results. (I'm using SQL 2000 EE SP3a.)
"Serge Shakhov" <REMOVETHIS_ACETYLENE@.mail.ru> wrote in message
news:q0ilmb.039.ln@.proxyserver.ctd.mmk.chel.su...
> Hello
> > select id,
> > [Rating] = case (abs(convert(int, convert(varbinary(4), newid())) %
> 5))
> > when 0 then NULL
> > when 1 then 'Poor'
> > when 2 then 'Fair'
> > when 3 then 'Good'
> > when 4 then 'Excellent'
> > else '?'
> > end
> > from sysobjects
> >
> >
> > I would expect this to return values in the range of 0-4, which would map
> to the various
> > strings that you see. However, I keep getting a high incidence of '?'
> strings returned.
> What version of SQL server are you using?
> I've tested your query on my MSSQL 2000 EE + SP3 and it works fine.
> Number of '?' is near the number of other variants.
>
> Serge Shakhov
>