Viewing 15 posts - 43,261 through 43,275 (of 59,102 total)
You've already written it. Look at the SELECT statement you built for the cursor. Just put the display in the text mode and let just that SELECT do...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 24, 2009 at 1:06 am
Of course, there's my favorite...
[font="Courier New"] SELECT t.N
FROM dbo.Tally t
WHERE t.N <= 100[/font]
You should Google the term "Tally Table" or click on the following link.
http://www.sqlservercentral.com/articles/T-SQL/62867/
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 11:50 pm
Of course, there's always the Itzik method...
[font="Courier New"] CREATE FUNCTION dbo.fnItzekNumsTest(@N AS BIGINT)
RETURNS TABLE
AS
RETURN
WITH
L0 AS (SELECT 1 AS C UNION ALL SELECT 1), --2 rows
L1 AS (SELECT 1 AS C FROM L0 AS A, L0 AS B),--4 rows
L2 AS (SELECT 1 AS C FROM L1 AS A, L1 AS B),--16 rows
L3 AS (SELECT 1 AS C FROM L2 AS A, L2 AS B),--256 rows
L4 AS (SELECT 1 AS C FROM L3 AS A, L3 AS B),--65536 rows
L5 AS (SELECT 1 AS C FROM L4 AS A, L4 AS B),--4294967296 rows
Nums AS (SELECT ROW_NUMBER() OVER (ORDER BY C) AS n FROM L5)
SELECT N FROM Nums WHERE n <= 100[/font]
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 11:43 pm
hi_abhay78 (6/23/2009)
WITH Numbers(Number) AS (
SELECT 1
UNION ALL
SELECT Number + 1
FROM Numbers
WHERE Number <= 99
)
SELECT *...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 11:36 pm
It sounds like you're using a cursor or while loop. What is it that you're doing that requires one?
As a side bar, you can get around the limitations of...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 11:12 pm
Will there ever be 3 rows?
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 8:38 pm
Steve Jones - Editor (6/23/2009)
I don't think anyone has crossed a line, but I see a few posts that are close. Please...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 7:48 pm
Paul White (6/23/2009)
Oh boy. So now "standard SQL" has been invoked.Jeff's gonna absolutely love this - I just hope Carl likes pork.
Heh... I never thought I'd tell someone to...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 7:45 pm
Charles Kincaid (6/22/2009)
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 7:39 pm
Never mind... wrong post. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 6:57 pm
Tom.Thomson (6/23/2009)
the foreign key constraint - but that only works if the target is (a) unique and (b) the primary key.
I'm pretty sure that only half of that is true....
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 6:24 pm
Eichpeel (6/23/2009)
code that humans can understand." -Martin Fowler et al, Refactoring: Improving the Design of Existing Code, 1999...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 4:21 pm
For this reason, I do not use these types of undocumented features
Look up UPDATE in BOL... the SET @variable = column = expression IS documented.
and also try to avoid...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 4:16 pm
Paul White (6/23/2009)
Using my preferred measure of total_worker_time as reported by sys.dm_exec_query_stats:
Triangular join: 10,218,749µs (~10.2 sec)
Your method:
Receipts running total: 41,015µs (~0.04 sec)
Shipments running total: 240,234µs (~0.24 sec)
Final SELECT: 4,425,781µs...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 4:09 pm
suneel (6/22/2009)
As I mentioned, we import the resultset of these SPs into Excel. But the columns that we display in each and every worksheet are dynamic. So, we are trying...
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2009 at 9:44 am
Viewing 15 posts - 43,261 through 43,275 (of 59,102 total)