Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jtrapat1
Starting Member
43 Posts |
Posted - 2003-03-17 : 10:12:23
|
| The query below is returning more than one value but I would only like to get the first value returned.Is this possible or is there some syntax to do this?Or, do I have to create a separate cursor to get a single value?Here is some of my output:24pederj 24personm 25pederj 25personm What I would like to get back is just one record, i.e, one id for each record. For example, 24pederj25pederjIs there an easy way to get this as my output?Thanks in Advance.John----------------------------------------------------------EXEC SQL DECLARE C1 CURSOR FOR SELECT bp12.adds_id, bp03.userid, bp10.fund_type, bp12.acct_code, bp04.prog_desc, bp02.agency_abbr, bp02.chapter FROM nysa.bp12t_approp_adds bp12 LEFT JOIN nysa.bp10t_appropriation bp10 ON bp12.appr_id = bp10.appr_id AND bp12.budget_yr = bp10.budget_yr LEFT JOIN nysa.bp02t_agency bp02 ON bp10.agency_code = bp02.agency_code AND bp10.budget_yr = bp02.budget_yr LEFT JOIN nysa.bp04t_agency_prog bp04 ON bp10.agency_code = bp04.agency_code AND bp10.prog_code = bp04.prog_code AND bp02.budget_yr = bp04.budget_yr LEFT JOIN nysa.bp03t_priv_agency bp03 ON bp02.parent_code = bp03.parent_code AND bp02.budget_yr = bp03.budget_yr LEFT JOIN nysa.bp01t_privilege bp01 ON bp03.userid = bp01.userid AND bp03.budget_yr = bp01.budget_yr WHERE bp12.budget_yr = :bp12.budget_yr AND bp01.role = 'ANAL' AND bp12.status = 'A' AND bp12.neg_code = :bp12.neg_code ORDER BY bp12.adds_id; ------------------------------------------------------- |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2003-03-17 : 10:27:06
|
| If you want cut-n-paste-able code, you'll need to post the ddl for your table. Looking at your "Here is some of my output:" example, I have no idea what your table looks like.Basically, you will need to group by something and aggregate something else.?AND bp01.role = 'ANAL'?...mkay...Jay White{0} |
 |
|
|
Arnold Fribble
Yak-finder General
1961 Posts |
Posted - 2003-03-17 : 11:42:07
|
quote: AND bp01.role = 'ANAL'
I was more worried about the colons, myself. |
 |
|
|
|
|
|
|
|