SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Help in a store procedure
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

marclas
Starting Member

Camaroon
16 Posts

Posted - 08/08/2012 :  10:38:15  Show Profile  Reply with Quote
Hi,
I have a Stro proc with many instructions among which this one [SQL] select cmp_id from CSR_COMPLEMENT
where DOS_ID = (select DOS_ID from CSR_DOSSIER where DOS_NODE = @DOS_NODE) order by cmp_numordre[/SQL]

if the number of row is 01, i can easily get the cmp_id, now how can i get the cmp_id when the number of row is more than one? in this case the cmp_id to take is the one with the higher cmp_numordre. from the result, I writing a new sql.

thanks

Marclas

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 08/08/2012 :  10:43:39  Show Profile  Reply with Quote
if there can be more than one rows replace = with IN


 select cmp_id from CSR_COMPLEMENT 
where DOS_ID IN (select DOS_ID from CSR_DOSSIER where DOS_NODE = @DOS_NODE) order by cmp_numordre


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Srinika
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 08/09/2012 :  12:21:08  Show Profile  Reply with Quote

select cmp_id from CSR_COMPLEMENT 
   where DOS_ID = (select top 1 DOS_ID from CSR_DOSSIER where   
                   DOS_NODE = @DOS_NODE order by cmp_numordre)
 order by cmp_numordre


Srinika
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 08/09/2012 :  12:48:42  Show Profile  Reply with Quote
quote:
Originally posted by Srinika


select cmp_id from CSR_COMPLEMENT 
   where DOS_ID = (select top 1 DOS_ID from CSR_DOSSIER where   
                   DOS_NODE = @DOS_NODE order by cmp_numordre desc)
 order by cmp_numordre


Srinika



as definition says
the cmp_id to take is the one with the higher cmp_numordre

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000