Re: Cursor
From: jduran (jduran_at_discussions.microsoft.com)
Date: 06/21/04
- Next message: David Portas: "Re: Help me designing that please"
- Previous message: Anith Sen: "Re: Database name with dash in job step database list"
- In reply to: Hugo Kornelis: "Re: Cursor"
- Next in thread: Hugo Kornelis: "Re: Cursor"
- Reply: Hugo Kornelis: "Re: Cursor"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 21 Jun 2004 13:08:01 -0700
Hugo,
I understand all your comments about the table. But unfortunately I did not design the table, nor do I have the authority to change it. Believe me I have tried.
You are correct I forgot to include the cursor. Here it is.
CREATE PROCEDURE dbo.ssp_fhkivr5
AS
SET NOCOUNT ON
-- declare all variables!
DECLARE
@HMO_Phone varchar(15)
Declare hmophone scroll cursor
for
Select top 100 fhk_hmo_phone
from tbl_fhk_child
for UPDATE of fhk_hmo_phone
open hmophone
fetch next from hmophone into @hmo_phone
while @@fetch_status = 0
Begin
UPDATE tbl_fhk_child
SET @hmo_phone = counthmo.hmo_phone,
fhk_hmo_phone = @hmo_phone
FROM tbl_fhk_child, counthmo, appl
WHERE
counthmo.HEALTH_PLAN = appl.HEALTH_PLAN
and appl.parent_id = tbl_fhk_child.fhk_parent_id;
fetch next from hmophone into @hmo_phone
end
deallocate hmophone
This cursor tells me it is Read Only.
"Hugo Kornelis" wrote:
> On Mon, 21 Jun 2004 09:06:02 -0700, jduran wrote:
>
> >Need help with a simple cursor.
>
> Hi jduran,
>
> No, you don't.
>
> First, your post doesn't have enough information to show what you are
> trying to achieve. You mention a cursor, but I see nothing that refers to
> a cursor. You give the definition for one of your tables, but not for the
> others; you don't give sample data and you don't explain what you are
> trying to achieve.
>
> Even without knowing what you are trying to do, I'm pretty sure it can be
> done without cursors. 99.9% of all things that need to be done in a
> database can be done with set-based queries, without cursors and in 99.8%
> of all cases is the set-based approach quicker and easier to maintain.
>
> If you want us to help you, include the following in your post:
> * DDL (CREATE TABLE statements) for ALL tables that are relevant to the
> problem. You may leave out the columns that are of no interest, but please
> do include all constraints!!
> * Sample data (in the form of INSERT statements - I like copy and paste
> almost as much as I dislike typing) for all relevant columns in all
> relevant tables.
> * Expected results after the query.
> * An explanation of how the supplied input leads to the expected results.
> * A description of the business problem you're trying to solve.
>
> With that, we can probably help you find an efficient, set-based solution
> for your problem.
>
> Oh, and before I forget it - you might want to look into your table
> designj first, before going any further. Your design is, in all honesty,
> quite a mess. Some questions you should ask yourself:
> * Why is every column NULLable?
> * Why are so many columns defined as nvarchar(50)? Do you really expect
> Katana characters in fhk_child_fname of fhk_state? Will your application
> really accept 50-character SSN's as input?
> * Please stop using that silly tbl_ prefix in front or your table name.
> Are you afraid that you forget it's a table? Will you actually change all
> your queries to change "tbl_" to "vw_" when the table changes and you
> create a view to ensure backwards compatibility?
> * Also, don't put fhk in front of each column name. A phone number is a
> phone number, regardless of the table it is stored in.
>
> I'll stop here, thought there's probably a lot more. Google this group for
> "Celko" + "ISO-11179" if you want to know it all (but be prepared if you
> consider me harsh - my post is as sweet as a love-letter in comparison
> with Celko on a mild day...).
>
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
- Next message: David Portas: "Re: Help me designing that please"
- Previous message: Anith Sen: "Re: Database name with dash in job step database list"
- In reply to: Hugo Kornelis: "Re: Cursor"
- Next in thread: Hugo Kornelis: "Re: Cursor"
- Reply: Hugo Kornelis: "Re: Cursor"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|