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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to catch values if sqlst return more rows

Author  Topic 

Mng
Yak Posting Veteran

59 Posts

Posted - 2011-01-10 : 07:44:30
Hi,

In a stored procedure, how can i catch if sqlstatement returns more than one row ?

DECLARE @courseid int
SET @courseid = (select COURSE_ID from CATEGORY_COURSE where groupid = 'as_rew')

The above example works good, if the query returns one value.

If it returns more than 10 values...how can i catch ?
can we declare array variables ? Plz help me

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2011-01-10 : 08:10:38
DECLARE @courseid int
SET @courseid = (select TOP 1 COURSE_ID from CATEGORY_COURSE where groupid = 'as_rew' ORDER BY SomeCol)

- Lumbago

My blog (yes, I have a blog now! just not that much content yet)
-> www.thefirstsql.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-10 : 11:16:00
for catching all values returned you need table variables.


DECLARE @temp table
(
@courseid int
)
INSERT @temp
select COURSE_ID from CATEGORY_COURSE where groupid = 'as_rew'


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

Go to Top of Page
   

- Advertisement -