Re: SQL HELP PLEASE!! Cursor only returns part of the data



"Simon Barnett" <sb@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:xARpi.21338$2U6.5520@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,

I would much appreciate some help with a work project that is due very
soon.

I have used a cursor to return the required result from a db table in
order for me to use in an ASP/VBScript webpage. This is the first time I
have used a cursor and am having problems.


Don't use a cursor. If you are inexperienced with SQL then it's better not
to use cursors at all. Instead, always try for a single query solution. Find
some examples to expand your knowledge of set-based SQL or get some advice
and assistance.

Here's my guess of what you intended. It's untested. If you had posted DDL
and sample data I could have tested it out.

SELECT KeyAccountability AS col1,
'keyacc' AS rowtype
FROM KeyAccountability
WHERE category = @var1
AND jobprofileid = @jobprofileID
UNION
SELECT category AS col1,
'cat' AS rowtype
FROM KeyAccountability
WHERE category = @var1
AND jobprofileid = @jobprofileID;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--


.



Relevant Pages

  • Re: Error adding command properties for stored procedure call
    ... I see you are using the SQL Native Client for SQL Server ... A server cursor is not allowed on a remote stored procedure or stored ... The stored procedure called is a test one that simply SELECTs the name field ... int InitializeAndConnect; ...
    (microsoft.public.data.oledb)
  • Row by Row Operations Help req
    ... Create temp table 1 ... Nigel,The cursor question is the SQL equivalent of the GOTOs / NO GOTOs ... question about whether the familiarity of procedural code is worth the ... leverages the strengths of SQL Server and is usually faster since it uses ...
    (microsoft.public.sqlserver.programming)
  • Re: C5 woes. How stable is VFP really?
    ... After that I close the SQL server cursor and work with my manual cursor instead. ... a VFP9 app on a really old machine ... app was under more "pressure", VFP showed ...
    (microsoft.public.fox.programmer.exchange)
  • Re: SQL HELP PLEASE!! Cursor only returns part of the data
    ... First of all, it's not the cursor as such that is bad, it is the looping. ... and re-writing it to handle set-based data will cost you more ... set-based solution do not perform well, ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Re: Using Cursors
    ... it seems I've stirred up a hornet's nest with my cursor question. ... finding the discussion valuable in my circumstances (moving from Oracle to ... SQL Server). ... > DECLARE curEpisode SCROLL CURSOR FOR ...
    (microsoft.public.sqlserver.programming)