Re: SQL HELP PLEASE!! Cursor only returns part of the data
- From: "Simon Barnett" <sb@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jul 2007 23:14:09 GMT
David,
I'm pretty basic with sql and thought that I needed a cursor but your
suggestion has worked.
Are cursors deemed as bad practice? Everyone I have spoken to says to
avoid them.
Many thanks
Simon
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@xxxxxxx> wrote in message
news:DeadnUdfnoYDoTXbRVnyhAA@xxxxxxxxxxxxxxx
"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
--
.
- Follow-Ups:
- Re: SQL HELP PLEASE!! Cursor only returns part of the data
- From: Erland Sommarskog
- Re: SQL HELP PLEASE!! Cursor only returns part of the data
- References:
- SQL HELP PLEASE!! Cursor only returns part of the data
- From: Simon Barnett
- Re: SQL HELP PLEASE!! Cursor only returns part of the data
- From: David Portas
- SQL HELP PLEASE!! Cursor only returns part of the data
- Prev by Date: Which general SQL NG is more active??
- Next by Date: Re: SQL HELP PLEASE!! Cursor only returns part of the data
- Previous by thread: Re: SQL HELP PLEASE!! Cursor only returns part of the data
- Next by thread: Re: SQL HELP PLEASE!! Cursor only returns part of the data
- Index(es):
Relevant Pages
|