SP returning duplicate values but I don't understand why

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Tue, 11 Jun 2002 23:08:55



I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

I have a table, which consists of 2 columns. An Identity (1,1) and a string
(VARCHAR(255)).

Sometimes I need to return the last 10 distinct strings from that table.
I've therefore created the following SP:

CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

INSERT INTO #TmpGroup

SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup NOT IN
(SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

DROP TABLE #TmpGroup

But this inserts all the records into #TmpGroup. How can this be? I thought
that the "SMMGroup NOT IN ..." would assure that there would be no
duplicates.

Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Narayana Vyas Kondredd » Tue, 11 Jun 2002 23:26:49


You might want to modify the SELECT in your INSERT statement to use DISTINCT
keyword
--
HTH,
Vyas, MVP (SQL Server)

http://vyaskn.tripod.com/


Quote:> I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> I have a table, which consists of 2 columns. An Identity (1,1) and a
string
> (VARCHAR(255)).

> Sometimes I need to return the last 10 distinct strings from that table.
> I've therefore created the following SP:

> CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> INSERT INTO #TmpGroup

> SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup NOT IN
> (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> DROP TABLE #TmpGroup

> But this inserts all the records into #TmpGroup. How can this be? I
thought
> that the "SMMGroup NOT IN ..." would assure that there would be no
> duplicates.

> Martin Moustgaard


 
 
 

SP returning duplicate values but I don't understand why

Post by Anith Se » Tue, 11 Jun 2002 23:24:05


To avoid DUPLICATEs use SELECT DISTINCT.

But this inserts all the records into #TmpGroup. How can this be?<<

Your INSERT INTO statement is an implicit transaction. At the
beginning there are no ROWs in the #TmpGroup table. Since the
SQL Statement does a "bulk" insert it does not do a row-by-row
comparison with the table in the subQuery. And hence all the rows
are inserted into the table.

Also, I am not sure why you need to use a #Temp table for this
purpose.

Quote:>> Sometimes I need to return the last 10 distinct strings from that

table.<<

If you mean "last 10" as the most recently added 10 ROWs in the
table, you can try something like

SELECT DISTINCT TOP 10 SMMGroup FROM tSalgMagasinerMaalgruppe
ORDER BY SMMID DESC

- Anith


Quote:> I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> I have a table, which consists of 2 columns. An Identity (1,1) and a
string
> (VARCHAR(255)).

> Sometimes I need to return the last 10 distinct strings from that table.
> I've therefore created the following SP:

> CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> INSERT INTO #TmpGroup

> SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup NOT IN
> (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> DROP TABLE #TmpGroup

> But this inserts all the records into #TmpGroup. How can this be? I
thought
> that the "SMMGroup NOT IN ..." would assure that there would be no
> duplicates.

> Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Tue, 11 Jun 2002 23:36:06


Unfortunately I can't use DISTINCT in this situation (if I'm wrong please
correct me :-). Because I use the SMMID to sort by in order to get the last
values first (I only need the last 10 unique strings). And I must include
SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
unique.

Do you have any other ideas?

Martin Moustgaard



> You might want to modify the SELECT in your INSERT statement to use
DISTINCT
> keyword
> --
> HTH,
> Vyas, MVP (SQL Server)

> http://vyaskn.tripod.com/



> > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > I have a table, which consists of 2 columns. An Identity (1,1) and a
> string
> > (VARCHAR(255)).

> > Sometimes I need to return the last 10 distinct strings from that table.
> > I've therefore created the following SP:

> > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > INSERT INTO #TmpGroup

> > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup NOT
IN
> > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > DROP TABLE #TmpGroup

> > But this inserts all the records into #TmpGroup. How can this be? I
> thought
> > that the "SMMGroup NOT IN ..." would assure that there would be no
> > duplicates.

> > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Narayana Vyas Kondredd » Tue, 11 Jun 2002 23:47:11


Here's an example:

SELECT DISTINCT TOP 3 ColumnName
FROM TableName
ORDER BY ColumnName DESC

--
HTH,
Vyas, MVP (SQL Server)

http://vyaskn.tripod.com/


> Unfortunately I can't use DISTINCT in this situation (if I'm wrong please
> correct me :-). Because I use the SMMID to sort by in order to get the
last
> values first (I only need the last 10 unique strings). And I must include
> SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> unique.

> Do you have any other ideas?

> Martin Moustgaard



> > You might want to modify the SELECT in your INSERT statement to use
> DISTINCT
> > keyword
> > --
> > HTH,
> > Vyas, MVP (SQL Server)

> > http://vyaskn.tripod.com/


message

> > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > I have a table, which consists of 2 columns. An Identity (1,1) and a
> > string
> > > (VARCHAR(255)).

> > > Sometimes I need to return the last 10 distinct strings from that
table.
> > > I've therefore created the following SP:

> > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > INSERT INTO #TmpGroup

> > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup
NOT
> IN
> > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > DROP TABLE #TmpGroup

> > > But this inserts all the records into #TmpGroup. How can this be? I
> > thought
> > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > duplicates.

> > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Anith Se » Tue, 11 Jun 2002 23:49:34


Would this work for you?

SELECT TOP 10
     MAX(SMMID),SMMGroup
FROM
     tSalgMagasinerMaalgruppe
GROUP BY
     SMMGroup
ORDER BY
     MAX(SMMID) DESC

- Anith


> Unfortunately I can't use DISTINCT in this situation (if I'm wrong please
> correct me :-). Because I use the SMMID to sort by in order to get the
last
> values first (I only need the last 10 unique strings). And I must include
> SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> unique.

> Do you have any other ideas?

> Martin Moustgaard



> > You might want to modify the SELECT in your INSERT statement to use
> DISTINCT
> > keyword
> > --
> > HTH,
> > Vyas, MVP (SQL Server)

> > http://vyaskn.tripod.com/


message

> > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > I have a table, which consists of 2 columns. An Identity (1,1) and a
> > string
> > > (VARCHAR(255)).

> > > Sometimes I need to return the last 10 distinct strings from that
table.
> > > I've therefore created the following SP:

> > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > INSERT INTO #TmpGroup

> > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup
NOT
> IN
> > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > DROP TABLE #TmpGroup

> > > But this inserts all the records into #TmpGroup. How can this be? I
> > thought
> > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > duplicates.

> > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Wed, 12 Jun 2002 01:24:36


But my problem is, that I need to sort by the index coulmn in order to get
the last 10 strings. And the only way to do this is by including that column
in the SELECT DISTINCT part of the statement. And because the index column
is contains unique values, I'll get duplicate string values in the
resultset.



> Here's an example:

> SELECT DISTINCT TOP 3 ColumnName
> FROM TableName
> ORDER BY ColumnName DESC

> --
> HTH,
> Vyas, MVP (SQL Server)

> http://vyaskn.tripod.com/



> > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
please
> > correct me :-). Because I use the SMMID to sort by in order to get the
> last
> > values first (I only need the last 10 unique strings). And I must
include
> > SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> > unique.

> > Do you have any other ideas?

> > Martin Moustgaard



> > > You might want to modify the SELECT in your INSERT statement to use
> > DISTINCT
> > > keyword
> > > --
> > > HTH,
> > > Vyas, MVP (SQL Server)

> > > http://vyaskn.tripod.com/


> message

> > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > I have a table, which consists of 2 columns. An Identity (1,1) and a
> > > string
> > > > (VARCHAR(255)).

> > > > Sometimes I need to return the last 10 distinct strings from that
> table.
> > > > I've therefore created the following SP:

> > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > INSERT INTO #TmpGroup

> > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup
> NOT
> > IN
> > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > DROP TABLE #TmpGroup

> > > > But this inserts all the records into #TmpGroup. How can this be? I
> > > thought
> > > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > > duplicates.

> > > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Wed, 12 Jun 2002 01:28:37


That seems to do the trick :-)

Thank you very mush, Anith.

Martin MOustgaard



> Would this work for you?

> SELECT TOP 10
>      MAX(SMMID),SMMGroup
> FROM
>      tSalgMagasinerMaalgruppe
> GROUP BY
>      SMMGroup
> ORDER BY
>      MAX(SMMID) DESC

> - Anith



> > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
please
> > correct me :-). Because I use the SMMID to sort by in order to get the
> last
> > values first (I only need the last 10 unique strings). And I must
include
> > SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> > unique.

> > Do you have any other ideas?

> > Martin Moustgaard



> > > You might want to modify the SELECT in your INSERT statement to use
> > DISTINCT
> > > keyword
> > > --
> > > HTH,
> > > Vyas, MVP (SQL Server)

> > > http://vyaskn.tripod.com/


> message

> > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > I have a table, which consists of 2 columns. An Identity (1,1) and a
> > > string
> > > > (VARCHAR(255)).

> > > > Sometimes I need to return the last 10 distinct strings from that
> table.
> > > > I've therefore created the following SP:

> > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > INSERT INTO #TmpGroup

> > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup
> NOT
> > IN
> > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > DROP TABLE #TmpGroup

> > > > But this inserts all the records into #TmpGroup. How can this be? I
> > > thought
> > > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > > duplicates.

> > > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Narayana Vyas Kondredd » Wed, 12 Jun 2002 01:32:50


Why don't you post your CREATE TABLE script, some sample data and the
desired output, to avoid the confusion?
--
HTH,
Vyas, MVP (SQL Server)

http://vyaskn.tripod.com/


> But my problem is, that I need to sort by the index coulmn in order to get
> the last 10 strings. And the only way to do this is by including that
column
> in the SELECT DISTINCT part of the statement. And because the index column
> is contains unique values, I'll get duplicate string values in the
> resultset.



> > Here's an example:

> > SELECT DISTINCT TOP 3 ColumnName
> > FROM TableName
> > ORDER BY ColumnName DESC

> > --
> > HTH,
> > Vyas, MVP (SQL Server)

> > http://vyaskn.tripod.com/


message

> > > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
> please
> > > correct me :-). Because I use the SMMID to sort by in order to get the
> > last
> > > values first (I only need the last 10 unique strings). And I must
> include
> > > SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> > > unique.

> > > Do you have any other ideas?

> > > Martin Moustgaard


meddelelse

> > > > You might want to modify the SELECT in your INSERT statement to use
> > > DISTINCT
> > > > keyword
> > > > --
> > > > HTH,
> > > > Vyas, MVP (SQL Server)

> > > > http://vyaskn.tripod.com/


> > message

> > > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > > I have a table, which consists of 2 columns. An Identity (1,1) and
a
> > > > string
> > > > > (VARCHAR(255)).

> > > > > Sometimes I need to return the last 10 distinct strings from that
> > table.
> > > > > I've therefore created the following SP:

> > > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > > INSERT INTO #TmpGroup

> > > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE
SMMGroup
> > NOT
> > > IN
> > > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > > DROP TABLE #TmpGroup

> > > > > But this inserts all the records into #TmpGroup. How can this be?
I
> > > > thought
> > > > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > > > duplicates.

> > > > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Steve Kas » Wed, 12 Jun 2002 01:42:58


Martin,

  (In case Vyas is still out for coffee)

  In SQL Server, you do not have to include the sort column in a
simple select query.  If that is a restriction because of something else, do
this:

select top 10 strGroup, max(lngSMMID) as maxSMMID
from tSalgMagasinerMaalgruppe
group by strGroup
order by maxSMMID desc

or

select strGroup
from (
  select top 10 strGroup, max(lngSMMID) as maxSMMID
  from tSalgMagasinerMaalgruppe
  group by strGroup
  order by maxSMMID desc
) X

Steve Kass
Drew University


> But my problem is, that I need to sort by the index coulmn in order to get
> the last 10 strings. And the only way to do this is by including that column
> in the SELECT DISTINCT part of the statement. And because the index column
> is contains unique values, I'll get duplicate string values in the
> resultset.



> > Here's an example:

> > SELECT DISTINCT TOP 3 ColumnName
> > FROM TableName
> > ORDER BY ColumnName DESC

> > --
> > HTH,
> > Vyas, MVP (SQL Server)

> > http://vyaskn.tripod.com/



> > > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
> please
> > > correct me :-). Because I use the SMMID to sort by in order to get the
> > last
> > > values first (I only need the last 10 unique strings). And I must
> include
> > > SMMID in the SELECT statement when I use DISTINCT and SMMID is allways
> > > unique.

> > > Do you have any other ideas?

> > > Martin Moustgaard



> > > > You might want to modify the SELECT in your INSERT statement to use
> > > DISTINCT
> > > > keyword
> > > > --
> > > > HTH,
> > > > Vyas, MVP (SQL Server)

> > > > http://vyaskn.tripod.com/


> > message

> > > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > > I have a table, which consists of 2 columns. An Identity (1,1) and a
> > > > string
> > > > > (VARCHAR(255)).

> > > > > Sometimes I need to return the last 10 distinct strings from that
> > table.
> > > > > I've therefore created the following SP:

> > > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > > INSERT INTO #TmpGroup

> > > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE SMMGroup
> > NOT
> > > IN
> > > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > > DROP TABLE #TmpGroup

> > > > > But this inserts all the records into #TmpGroup. How can this be? I
> > > > thought
> > > > > that the "SMMGroup NOT IN ..." would assure that there would be no
> > > > > duplicates.

> > > > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Wed, 12 Jun 2002 15:14:54


I'll do that next time I have problems :-)

For now, the solution that Anith and Steve posted using GROUP BY works like
a charm :-)

Thank you for your replies.

Martin Moustgaard



> Why don't you post your CREATE TABLE script, some sample data and the
> desired output, to avoid the confusion?
> --
> HTH,
> Vyas, MVP (SQL Server)

> http://vyaskn.tripod.com/



> > But my problem is, that I need to sort by the index coulmn in order to
get
> > the last 10 strings. And the only way to do this is by including that
> column
> > in the SELECT DISTINCT part of the statement. And because the index
column
> > is contains unique values, I'll get duplicate string values in the
> > resultset.



> > > Here's an example:

> > > SELECT DISTINCT TOP 3 ColumnName
> > > FROM TableName
> > > ORDER BY ColumnName DESC

> > > --
> > > HTH,
> > > Vyas, MVP (SQL Server)

> > > http://vyaskn.tripod.com/


> message

> > > > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
> > please
> > > > correct me :-). Because I use the SMMID to sort by in order to get
the
> > > last
> > > > values first (I only need the last 10 unique strings). And I must
> > include
> > > > SMMID in the SELECT statement when I use DISTINCT and SMMID is
allways
> > > > unique.

> > > > Do you have any other ideas?

> > > > Martin Moustgaard


> meddelelse

> > > > > You might want to modify the SELECT in your INSERT statement to
use
> > > > DISTINCT
> > > > > keyword
> > > > > --
> > > > > HTH,
> > > > > Vyas, MVP (SQL Server)

> > > > > http://vyaskn.tripod.com/


> > > message

> > > > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > > > I have a table, which consists of 2 columns. An Identity (1,1)
and
> a
> > > > > string
> > > > > > (VARCHAR(255)).

> > > > > > Sometimes I need to return the last 10 distinct strings from
that
> > > table.
> > > > > > I've therefore created the following SP:

> > > > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > > > INSERT INTO #TmpGroup

> > > > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE
> SMMGroup
> > > NOT
> > > > IN
> > > > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > > > DROP TABLE #TmpGroup

> > > > > > But this inserts all the records into #TmpGroup. How can this
be?
> I
> > > > > thought
> > > > > > that the "SMMGroup NOT IN ..." would assure that there would be
no
> > > > > > duplicates.

> > > > > > Martin Moustgaard

 
 
 

SP returning duplicate values but I don't understand why

Post by Martin Moustgaar » Wed, 12 Jun 2002 15:31:02


Hello Steve.

If I try to execute the following in Query Analyzer:

SELECT DISTINCT SMMGroup FROM tSalgMagasinerMaalgruppe ORDER BY SMMID

I get this response:

Server: Msg 145, Level 15, State 1, Line 2
ORDER BY items must appear in the select list if SELECT DISTINCT is
specified.

So it seems as if SQL Server 7 wants me to put SMMID in the SELECT part of
the statement, if I want to use it as a sort column. But using GROUP BY
works perfect :-)

Martin Moustgaard



> Martin,

>   (In case Vyas is still out for coffee)

>   In SQL Server, you do not have to include the sort column in a
> simple select query.  If that is a restriction because of something else,
do
> this:

> select top 10 strGroup, max(lngSMMID) as maxSMMID
> from tSalgMagasinerMaalgruppe
> group by strGroup
> order by maxSMMID desc

> or

> select strGroup
> from (
>   select top 10 strGroup, max(lngSMMID) as maxSMMID
>   from tSalgMagasinerMaalgruppe
>   group by strGroup
>   order by maxSMMID desc
> ) X

> Steve Kass
> Drew University


> > But my problem is, that I need to sort by the index coulmn in order to
get
> > the last 10 strings. And the only way to do this is by including that
column
> > in the SELECT DISTINCT part of the statement. And because the index
column
> > is contains unique values, I'll get duplicate string values in the
> > resultset.



> > > Here's an example:

> > > SELECT DISTINCT TOP 3 ColumnName
> > > FROM TableName
> > > ORDER BY ColumnName DESC

> > > --
> > > HTH,
> > > Vyas, MVP (SQL Server)

> > > http://vyaskn.tripod.com/


message

> > > > Unfortunately I can't use DISTINCT in this situation (if I'm wrong
> > please
> > > > correct me :-). Because I use the SMMID to sort by in order to get
the
> > > last
> > > > values first (I only need the last 10 unique strings). And I must
> > include
> > > > SMMID in the SELECT statement when I use DISTINCT and SMMID is
allways
> > > > unique.

> > > > Do you have any other ideas?

> > > > Martin Moustgaard


meddelelse

> > > > > You might want to modify the SELECT in your INSERT statement to
use
> > > > DISTINCT
> > > > > keyword
> > > > > --
> > > > > HTH,
> > > > > Vyas, MVP (SQL Server)

> > > > > http://vyaskn.tripod.com/


> > > message

> > > > > > I'm using SQL server 7.0, SP3 on NT 4.0 server, SP6a

> > > > > > I have a table, which consists of 2 columns. An Identity (1,1)
and a
> > > > > string
> > > > > > (VARCHAR(255)).

> > > > > > Sometimes I need to return the last 10 distinct strings from
that
> > > table.
> > > > > > I've therefore created the following SP:

> > > > > > CREATE TABLE #TmpGroup (lngSMMID INT, strGroup VARCHAR(255))

> > > > > > INSERT INTO #TmpGroup

> > > > > > SELECT SMMID, SMMGroup FROM tSalgMagasinerMaalgruppe WHERE
SMMGroup
> > > NOT
> > > > IN
> > > > > > (SELECT strGroup FROM #TmpGroup) ORDER BY SMMID DESC

> > > > > > SELECT * FROM #TmpGroup ORDER BY lngSMMID DESC

> > > > > > DROP TABLE #TmpGroup

> > > > > > But this inserts all the records into #TmpGroup. How can this
be? I
> > > > > thought
> > > > > > that the "SMMGroup NOT IN ..." would assure that there would be
no
> > > > > > duplicates.

> > > > > > Martin Moustgaard

 
 
 

1. Help: SO get's hidden and I don't understand why

Hi,

I am currently struggling with SO's and I found this strange behaveour. I
try to explain.

I have a SmartWindow (say a.w) that is a container for 1 SDO and 2 SW's. I
run a.w from another SO, which is a SmartDataField (say b.w). The idea is
that a.w should give the user the opportunity to make some kind of selection
and upon termination of a.w, the results should be returned to the
SmartDataField and displayed there.

(I hope sofar I haven't said anything strange SmartObject-wise!)

I run my code from within the AppBuilder (just to test). No all is well,
until I close down a.w. Instead of seeing a.w dissapear and focus being
returned to b.w, everything disappears but the AppBuilder tells me there is
still something running. I consider that strange (at least not what I
anticipated).

Upon closer investigation in de debugger, I saw that the procedure
'hideObject' in a.w's smart.p is responsible for this behaveour. Apparently
it searches it's container-handle and hides that one. Something like this:

  {get ContainerHandle hContainer}.

  IF VALID-HANDLE(hContainer) THEN
         ASSIGN hContainer:HIDDEN = YES.

I don't understand why this happens. I can understand that an object hides
itself before termination, but I don't understand why the handle of b.w
seems to be used to hide it as well! When I display the values of the
handles of a.w, b.w and even the handle of b.w's frame, they are not the
same!

Can anyone out there shed some light on this and, more importantly, tell me
what to do to prevent this from happening?

(I hope I have stated my problem and my questions clearly enough)

TIA

Pieter Brouwer.

2. How to record a wave sound object ?

3. I don't understand why this view is not updatable

4. US - San Diego - Oracle DBA

5. Don't understand why it is ambiguous

6. SQL queries with Paradox

7. I don't understand why this worked in 7.0 and now not in 2000

8. Question re use of SQL in Delphi database app

9. Event ID:17045 don't understand why

10. Getting Error 13, help - don't understand why

11. Don't duplicate v Don't resend trade-off theory

12. Don't know how to get parameters returned from sp using ADO

13. why the identity values don't enter while importing data from Excel