Re: potential top
From: Philippe [MS] (ptrotin_at_online.microsoft.com)
Date: 10/19/04
- Next message: Anith Sen: "Re: Toolbar in Design View of a table?"
- Previous message: Philippe [MS]: "Re: SET NOCOUNT ON OPTION"
- In reply to: CGW: "Re: potential top"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 19 Oct 2004 21:32:15 +0200
If needed, I have wrote a store procedure allowing you to go from a specific
row number to another.
Example : EXEC tp_GetSqlRange 'SELECT * FROM Zip', 'ZIP_ID', 5, 10
=> get the row from 5 to 10 based on the ZIP_ID (for order by and
unicity.)
Hope this can help.
Phil.
"CGW" <CGW@discussions.microsoft.com> wrote in message
news:672D580A-70B6-464A-B3CA-5EFEF4081F1C@microsoft.com...
> Thanks for a creative solution. Though it doesn't exactly fit what we need
> here, it sure looks like something handy for later.
>
> Thank you.
>
> CGW
>
> "Adam Machanic" wrote:
>
> >
> > "CGW" <CGW@discussions.microsoft.com> wrote in message
> > news:A5842788-5254-4653-9EB3-889784F48D09@microsoft.com...
> > > When executing a top query, is there a way to return (in the same
query) a
> > > rowcount for what the query would return without the top?
> > >
> > > For example
> > > SELECT TOP 100 FROM MyTable WHERE MyCondition
> > > Can I add something to that query to return what the COUNT (*) would
be
> > > without the "top 100" at the same time as the top 100 records. A
second
> > > query, in this environment, is costly.
> >
> > Depending on how much data you're talking about, it might actually
be
> > cheaper to do the entire select into a temp table and then select TOP
100
> > and the COUNT(*) from that:
> >
> > SELECT x, y, z
> > INTO #SomeTable
> > FROM MyTable
> > WHERE MyCondition
> >
> > SELECT TOP 100 x, y, z
> > FROM #SomeTable
> > ORDER BY x
> >
> > SELECT COUNT(*)
> > FROM #SomeTable
> >
> > Alternatively, if you're dealing with big LOB columns (which would
be
> > expensive to move into the temp table), you could just select the
primary
> > keys into the temp table and then pull back the data from the main table
> > that way:
> >
> > SELECT PK, x
> > INTO #SomeTable
> > FROM MyTable
> > WHERE MyCondition
> >
> > SELECT x, y, z
> > FROM MyTable
> > WHERE PK IN
> > (SELECT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`" `00!.`%,`20!?`$X`50!,`$P`4P`@`$\`3@`@``T`
."@!'`$\`#0`*``T`"@``
`
end
- Next message: Anith Sen: "Re: Toolbar in Design View of a table?"
- Previous message: Philippe [MS]: "Re: SET NOCOUNT ON OPTION"
- In reply to: CGW: "Re: potential top"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|