For each selection SQL 2005

The following query is used to fill a cursor. I only want one row in the cursor for each PlmName

I need the fields to process data within the cursor.

How do I load the cursor with one row of data related to PlmName?


                       OEM_PLM_OPRICE AS PPR ON PNT.PartID = PPR.PartID INNER JOIN
                       OEM_PLM_THRESHHOLD ON PNT.LicenseCode = OEM_PLM_THRESHHOLD.License_Code AND 
                       PPR.TotalCompPrice > OEM_PLM_THRESHHOLD.Threshhold_amt 
more ▼

asked Sep 06, 2012 at 08:32 PM in Default

avatar image

1.4k 100 113 120

I don't get it. You have a query, which you use to populate a cursor now. Apart from a cursor-based solution probably being unnecessary and definetily being inefficient: What's the problem with what you have so far? What does it result in, and how does it differ from your desired result?

Sep 07, 2012 at 03:57 AM Magnus Ahlkvist

Yeah, I'm at a loss to understand what's needed here too. Also, in general, if you find yourself thinking in terms of "FOR EACH" in SQL Server, you might be digging a hole. Always think in terms of sets and batches. That's how the T-SQL language usually works best.

Sep 07, 2012 at 10:49 AM Grant Fritchey ♦♦

Sorry to bug you. I modified how I was filling the cursor and the email that is sent within the cursor now sends a nicely formatted table with the data so that each representative will only receive one email every night with the data they need to pay attention to.

Sep 07, 2012 at 06:55 PM technette

So is this no longer a problem for you?

Sep 10, 2012 at 08:57 AM ThomasRushton ♦♦
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

It seems to me that the simplest way is to just take the email out of the select distinct clause. That should give you 1 row per name. Then to get the email, you can do a sub-select.

more ▼

answered Sep 19, 2012 at 07:32 PM

avatar image

170 2 3

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Sep 06, 2012 at 08:32 PM

Seen: 631 times

Last Updated: Sep 19, 2012 at 07:32 PM

Copyright 2016 Redgate Software. Privacy Policy