March 20, 2010 at 8:32 pm
Yeah, I know...cursors...yuk. Lets try to move past that for a second...
So what does it mean when I have a SELECT statement like this:
SELECT
Name
FROM
Customer
WHERE
CustomerID=1
With Results that say:
Name
----------------
Mike
(1 row(s) affected)
But then when I use the same SELECT as part of a cursor and do this:
--Temp table to hold all results
CREATE TABLE #tempTable (Colvalue1 VARCHAR(2000))
--Variablel to hold cursor results
DECLARE @col1 VARCHAR(200)
--Cursor
DECLARE Temp_curs CURSOR FOR
SELECT
Name
FROM
Customer
WHERE
CustomerID=1
OPEN Temp_curs
/*GET THE FIRST RECORD AND LOAD VARIABLES WITH COLUMN DATA*/
FETCH NEXT FROM Temp_curs
INTO @col1
WHILE @@FETCH_STATUS=0
BEGIN
INSERT INTO #tempTable(Colvalue1)
VALUES(@col1)
FETCH NEXT FROM Temp_curs
INTO @col1
END
/*CLOSE CURSOR AND DEALLOCATE SPACE*/
CLOSE Temp_curs
DEALLOCATE Temp_curs
SELECT * FROM #tempTable
Return results like:
Name
----------------
0
(1 row(s) affected)
Other than the obvious poor performance...WTH is going on here?! I'm in the process of confirming this is only happening on one machine...this is crazy! :crazy:
March 20, 2010 at 8:49 pm
Never mind...customer had some outdated code with mistakes in it. The problem code was simply putting values into @coll (lower case "L") instead of @col1 (number "1")...looks almost identical within certain font families. :blush:
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy