How to find where the Select statement returns value or not

Posted by Sathya4260 under Sql Server on 4/6/2011 | Points: 10 | Views : 1642 | Status : [Member] | Replies : 3
Hi,

I having an stored procedure, in which an "Select statement is there using where condition" like

"Select studentid from students where studentname=@studentname"

Now i need to find where the select statement returns value or not in stored procedure,

So i can write the sql statements as per the above condition

Thanks in advance...

Sathish Kumar S


Responses

Posted by: SheoNarayan on: 4/6/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Fire the ExecuteScalar method something like

object obj =  cmd.ExecuteScalar

if (obj!=null)
{
// fire another select statement as your stored procedure is returning a record
}


Hope this is what you are looking for.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Sathya4260, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sathya4260 on: 4/6/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Narayan,

I need to find out inside the stored procedure

Sathish Kumar S

Sathya4260, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: PandianS on: 4/8/2011 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi

If you want to verify, whether the statement returns row / not
IF EXISTS(Select 1 from students where studentname=@studentname)

-------If it returns any row
ELSE
-------If it not returns any row
If you want to proceed further based on the results

Select studentid from students where studentname=@studentname

If @@Rowcount >0
-------If it returns any row
Else
-------If it not returns any row


Cheers


Cheers
www.SQLServerbuddy.blogspot.com
iLink Multitech Solutions

Sathya4260, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response