have stored proc always return a blank recordhttp://forums.asp.net/t/1789759.aspx/1?have+stored+proc+always+return+a+blank+recordFri, 06 Apr 2012 13:38:51 -040017897594918646http://forums.asp.net/p/1789759/4918646.aspx/1?have+stored+proc+always+return+a+blank+recordhave stored proc always return a blank record <p>Using sql server 2005</p> <p>I have a stored proc that is a query and when there is no data return I still want the query to return an empty record with NULLs. whats an easy way to do this?</p> <p>I've done this before using temp tables but wwondering about an easier way</p> <p>thanks</p> <p>MC</p> <p></p> 2012-04-05T20:26:27-04:004918653http://forums.asp.net/p/1789759/4918653.aspx/1?Re+have+stored+proc+always+return+a+blank+recordRe: have stored proc always return a blank record <p></p> <p>you can use like this in your store procedure if its only use to get the data</p> <p></p> <p>IF EXISTS (SELECT * FROM TableName WHERE COLUMN2 = @value1 AND COLUMN2 = @value2)<br> BEGIN<br> -- your query if the data exists in database<br> END<br> ELSE<br> SELECT NULL AS NoValue</p> <p></p> <p>Hope it will solve your issue</p> 2012-04-05T20:39:22-04:004918656http://forums.asp.net/p/1789759/4918656.aspx/1?Re+have+stored+proc+always+return+a+blank+recordRe: have stored proc always return a blank record <pre class="prettyprint">IF EXISTS(SELECT * FROM MyTable WHERE Condition=true) SELECT * FROM MyTable WHERE Condition=true ELSE SELECT NULL AS Column1, NULL AS Column2, NULL AS Column3, [etc...]</pre> <p></p> 2012-04-05T20:41:18-04:004919709http://forums.asp.net/p/1789759/4919709.aspx/1?Re+have+stored+proc+always+return+a+blank+recordRe: have stored proc always return a blank record <p></p> <blockquote><span class="icon-blockquote"></span> <h4>TabAlleman</h4> <p></p> <pre class="prettyprint">IF EXISTS(SELECT * FROM MyTable WHERE Condition=true) SELECT * FROM MyTable WHERE Condition=true ELSE SELECT NULL AS Column1, NULL AS Column2, NULL AS Column3, [etc...]</pre> <p></p> <p></p> </blockquote> <p></p> <p>very nice, I like it.</p> <p>this works well assuming the initial exists query is fast, if its slow i guess you would have to weigh using a temp table vs using what you did above</p> 2012-04-06T13:38:51-04:00