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)
 Make sure that SP do not return null

Author  Topic 

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-22 : 10:38:22
I code a SP to return data:
select * from #temp
Two questions"
1) how to make sure that sp do not return null or nothing?
2) if no data to return, what code to handle?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-22 : 11:10:00
It is up to the developer to handle these scenarios in accordance with the project specifications. What specific problem are you trying to solve? The code you use is dependent on what you want to have happen

For instance, a search SP probably should return an empty result set if the user searches for something that doesn't exist. The application should check for that and display an appropriate message.

Be One with the Optimizer
TG
Go to Top of Page

Sun Foster
Aged Yak Warrior

515 Posts

Posted - 2009-09-22 : 11:26:33
I use this sp to process data and then return final. I am expect data to return but sometime is not. In app, I use this sp to create a dataset but if nothing to return, will cause en error "Object reference not set to an instance of an object."
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-09-22 : 11:35:24
The Object reference error is probably because of an error somewhere. Either a timeout because it takes too long for you command and/or connection timeout value or a sql error in your SP. Run the SP in a query window to see how long it takes and if any sql errors are being raised.

EDIT:
also check the event log of the machine that your app runs on for errors.

EDIT2:
another possibility is that you are getting results but one or more of your column values are DBNull and your application isn't taking that possibility into account.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -