Showing posts with label statement. Show all posts
Showing posts with label statement. Show all posts

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 ?

I have an Access database that retrieves view definitions from an SQL server
database. I use this statement to get the view definitions :
select TABLE_NAME as VIEW_NAME,VIEW_DEFINITION
from INFORMATION_SCHEMA.VIEWS
I have a view thet is more then 4000 characters and then the call against
INFORMATION_SCHEMA returns NULL for the VIEW_DEFINITION. Why ?
If i query the syscomments table the view is splitted in two columns.
Regards
Robert Vabo
Senior developer
Gecko Informasjonssystemer AS
rv_nospam@.gecko.no
Remove the _nospam to send mail !
www.gecko.noDo you mean rows or columns in the syscomments table'
--
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
"Robert Vabo" <rvabo@.msn.com> wrote in message
news:%23jK0CCh8DHA.2116@.TK2MSFTNGP10.phx.gbl...
> I have an Access database that retrieves view definitions from an SQL
server
> database. I use this statement to get the view definitions :
> select TABLE_NAME as VIEW_NAME,VIEW_DEFINITION
> from INFORMATION_SCHEMA.VIEWS
> I have a view thet is more then 4000 characters and then the call against
> INFORMATION_SCHEMA returns NULL for the VIEW_DEFINITION. Why ?
> If i query the syscomments table the view is splitted in two columns.
>
> --
> Regards
> Robert Vabo
> Senior developer
> Gecko Informasjonssystemer AS
> rv_nospam@.gecko.no
> Remove the _nospam to send mail !
> www.gecko.no
>|||Sorry. I mean rows ofcourse.
But the problem is that the column VIEW_DEFINITION returns NULL when
querying the INFORMATION_SCHEMA
Regards
Robert Vabo
Senior developer
Gecko Informasjonssystemer AS
rv_nospam@.gecko.no
Remove the _nospam to send mail !
www.gecko.no
"SriSamp" <ssampath@.sct.co.in> skrev i melding
news:%23YBXKkh8DHA.452@.TK2MSFTNGP11.phx.gbl...
> Do you mean rows or columns in the syscomments table'
> --
> HTH,
> SriSamp
> Please reply to the whole group only!
> http://www32.brinkster.com/srisamp
> "Robert Vabo" <rvabo@.msn.com> wrote in message
> news:%23jK0CCh8DHA.2116@.TK2MSFTNGP10.phx.gbl...
> server
against
>

BUG in SQL SERVER 2000 ?

I have an Access database that retrieves view definitions from an SQL server
database. I use this statement to get the view definitions :
select TABLE_NAME as VIEW_NAME,VIEW_DEFINITION
from INFORMATION_SCHEMA.VIEWS
I have a view thet is more then 4000 characters and then the call against
INFORMATION_SCHEMA returns NULL for the VIEW_DEFINITION. Why ?
If i query the syscomments table the view is splitted in two columns.
--
Regards
Robert Vabo
Senior developer
Gecko Informasjonssystemer AS
rv_nospam@.gecko.no
Remove the _nospam to send mail !
www.gecko.noDo you mean rows or columns in the syscomments table'
--
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp
"Robert Vabo" <rvabo@.msn.com> wrote in message
news:%23jK0CCh8DHA.2116@.TK2MSFTNGP10.phx.gbl...
> I have an Access database that retrieves view definitions from an SQL
server
> database. I use this statement to get the view definitions :
> select TABLE_NAME as VIEW_NAME,VIEW_DEFINITION
> from INFORMATION_SCHEMA.VIEWS
> I have a view thet is more then 4000 characters and then the call against
> INFORMATION_SCHEMA returns NULL for the VIEW_DEFINITION. Why ?
> If i query the syscomments table the view is splitted in two columns.
>
> --
> Regards
> Robert Vabo
> Senior developer
> Gecko Informasjonssystemer AS
> rv_nospam@.gecko.no
> Remove the _nospam to send mail !
> www.gecko.no
>|||Sorry. I mean rows ofcourse.
But the problem is that the column VIEW_DEFINITION returns NULL when
querying the INFORMATION_SCHEMA
--
Regards
Robert Vabo
Senior developer
Gecko Informasjonssystemer AS
rv_nospam@.gecko.no
Remove the _nospam to send mail !
www.gecko.no
"SriSamp" <ssampath@.sct.co.in> skrev i melding
news:%23YBXKkh8DHA.452@.TK2MSFTNGP11.phx.gbl...
> Do you mean rows or columns in the syscomments table'
> --
> HTH,
> SriSamp
> Please reply to the whole group only!
> http://www32.brinkster.com/srisamp
> "Robert Vabo" <rvabo@.msn.com> wrote in message
> news:%23jK0CCh8DHA.2116@.TK2MSFTNGP10.phx.gbl...
> > I have an Access database that retrieves view definitions from an SQL
> server
> > database. I use this statement to get the view definitions :
> > select TABLE_NAME as VIEW_NAME,VIEW_DEFINITION
> > from INFORMATION_SCHEMA.VIEWS
> >
> > I have a view thet is more then 4000 characters and then the call
against
> > INFORMATION_SCHEMA returns NULL for the VIEW_DEFINITION. Why ?
> > If i query the syscomments table the view is splitted in two columns.
> >
> >
> > --
> > Regards
> > Robert Vabo
> > Senior developer
> > Gecko Informasjonssystemer AS
> > rv_nospam@.gecko.no
> > Remove the _nospam to send mail !
> > www.gecko.no
> >
> >
>

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
>

Tuesday, February 14, 2012

Break statement does not work

I am trying to delete 500000 rows at a time from a big table. I am trying to
loop through it. I am attaching my code, what am I doing wrong. It either
will delete only 500000 rows and exit ot it will keep on looping. I am askin
g
it to delete data older than a certain date. If there are 3000000 rows , I
want it to loop till it deletes 3000000 rows and then exit. Instead if i set
the loop counter to 10, it will loop ten times and then exit. The break
statement does not work
here is the code
declare @.i int
select @.i=10
set rowcount 1000000
while @.i>0
begin
delete from flat_reporttbl
where logdate<'4/1/2004'
select @.i=@.i-1
break
end
thankscheck it.
delete top(10) from flat_reporttbl
where logdate<'4/1/2004'
the problem in ur code is ,
delete statement deletes all rows
which satisfies the condition in
where clause and
then check the while condition.
"batgirl" <batgirl@.discussions.microsoft.com> wrote in message
news:49793BEE-8D40-480E-8D5A-03E77A45A541@.microsoft.com...
>I am trying to delete 500000 rows at a time from a big table. I am trying
>to
> loop through it. I am attaching my code, what am I doing wrong. It either
> will delete only 500000 rows and exit ot it will keep on looping. I am
> asking
> it to delete data older than a certain date. If there are 3000000 rows , I
> want it to loop till it deletes 3000000 rows and then exit. Instead if i
> set
> the loop counter to 10, it will loop ten times and then exit. The break
> statement does not work
> here is the code
> declare @.i int
> select @.i=10
> set rowcount 1000000
> while @.i>0
> begin
> delete from flat_reporttbl
> where logdate<'4/1/2004'
> select @.i=@.i-1
> break
> end
> thanks|||I don't know if we can use the TOP keyword with delete. It gives me an error
message when I try to use it. Also I have already set the rowcount, so does
using TOP help?
batgirl
"batgirl" wrote:

> I am trying to delete 500000 rows at a time from a big table. I am trying
to
> loop through it. I am attaching my code, what am I doing wrong. It either
> will delete only 500000 rows and exit ot it will keep on looping. I am ask
ing
> it to delete data older than a certain date. If there are 3000000 rows , I
> want it to loop till it deletes 3000000 rows and then exit. Instead if i s
et
> the loop counter to 10, it will loop ten times and then exit. The break
> statement does not work
> here is the code
> declare @.i int
> select @.i=10
> set rowcount 1000000
> while @.i>0
> begin
> delete from flat_reporttbl
> where logdate<'4/1/2004'
> select @.i=@.i-1
> break
> end
> thanks

Break line inside print statement

Hello,
I need to break one line that im printing inside one script. The line is very large and i don=B4t know how to do it.
Best RegardsNot sure exactly what you mean, but perhaps below?
SELECT 'Hello' + CHAR(13) + CHAR(10) + 'there'
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message news:9c5101c43422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i don´t know how to do
it.
Best Regards|||I'm not sure I understand correctly but
select "Hello" + char(13) + char(10) + "World"
will come out as
Hello
World
rgds
Paul
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:9c5101c43422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i don´t know how to do
it.
Best Regards

Break line inside print statement

Hello,
I need to break one line that im printing inside one=20
script. The line is very large and i don=B4t know how to do=20
it.
Best Regards
Not sure exactly what you mean, but perhaps below?
SELECT 'Hello' + CHAR(13) + CHAR(10) + 'there'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message news:9c5101c43422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i dont know how to do
it.
Best Regards
|||I'm not sure I understand correctly but
select "Hello" + char(13) + char(10) + "World"
will come out as
Hello
World
rgds
Paul
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:9c5101c43422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i dont know how to do
it.
Best Regards

Break line inside print statement

Hello,
I need to break one line that im printing inside one=20
script. The line is very large and i don=B4t know how to do=20
it.
Best RegardsNot sure exactly what you mean, but perhaps below?
SELECT 'Hello' + CHAR(13) + CHAR(10) + 'there'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message news:9c5101c4
3422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i dont know how to do
it.
Best Regards|||I'm not sure I understand correctly but
select "Hello" + char(13) + char(10) + "World"
will come out as
Hello
World
rgds
Paul
"CC&JM" <anonymous@.discussions.microsoft.com> wrote in message
news:9c5101c43422$e3448ef0$a101280a@.phx.gbl...
Hello,
I need to break one line that im printing inside one
script. The line is very large and i dont know how to do
it.
Best Regards