dbTalk Databases Forums  

MS SQL for returning no values

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss MS SQL for returning no values in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ben
 
Posts: n/a

Default MS SQL for returning no values - 11-20-2007 , 04:57 AM






Hello,

im having a problem integrating an SQL statement with my program,
it works fine when theres a result but throws an error when there is
no result,
is there anyway in SQL to make up a row if there isnt one that matches
the query for example in this i could put indicator values in the
returned fields then a simple check to see if its a proper field of my
indicator field

I know ISNULL works with single values but that only works if there is
a row returned

Does anyone know of any SQL syntax for MS SQL that when no row is
returned it makes on up and parses it back

Thank you in advance for your help!!

Ben

Reply With Quote
  #2  
Old   
Helmut Woess
 
Posts: n/a

Default Re: MS SQL for returning no values - 11-20-2007 , 07:31 AM






Am Tue, 20 Nov 2007 02:57:06 -0800 (PST) schrieb Ben:

Quote:
Hello,

im having a problem integrating an SQL statement with my program,
it works fine when theres a result but throws an error when there is
no result,
.... and what is the error message ??

Quote:
Does anyone know of any SQL syntax for MS SQL that when no row is
returned it makes on up and parses it back
I don't see any sense in this, but anyway, you can do something like:

if (select count(*) from persontable where id < 17) > 0
select id, lastname, street1, city from persontable where id < 17
else select 0 as id, 'testperson' as lastname, 'noStreet' as street1,
'noCity' as city

bye,
Helmut


Reply With Quote
  #3  
Old   
Jason Lepack
 
Posts: n/a

Default Re: MS SQL for returning no values - 11-20-2007 , 07:33 AM



What language is your "Program" in? Check the recordcount on the
dataset returned and go from there, don't return the dummy record.

Cheers,
Jason Lepack


On Nov 20, 5:57 am, Ben <bor... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

im having a problem integrating an SQL statement with my program,
it works fine when theres a result but throws an error when there is
no result,
is there anyway in SQL to make up a row if there isnt one that matches
the query for example in this i could put indicator values in the
returned fields then a simple check to see if its a proper field of my
indicator field

I know ISNULL works with single values but that only works if there is
a row returned

Does anyone know of any SQL syntax for MS SQL that when no row is
returned it makes on up and parses it back

Thank you in advance for your help!!

Ben


Reply With Quote
  #4  
Old   
Ben
 
Posts: n/a

Default Re: MS SQL for returning no values - 11-20-2007 , 08:34 AM



On 20 Nov, 13:33, Jason Lepack <jlep... (AT) gmail (DOT) com> wrote:
Quote:
What language is your "Program" in? Check the recordcount on the
dataset returned and go from there, don't return the dummy record.

Cheers,
Jason Lepack

On Nov 20, 5:57 am, Ben <bor... (AT) gmail (DOT) com> wrote:



Hello,

im having a problem integrating an SQL statement with my program,
it works fine when theres a result but throws an error when there is
no result,
is there anyway in SQL to make up a row if there isnt one that matches
the query for example in this i could put indicator values in the
returned fields then a simple check to see if its a proper field of my
indicator field

I know ISNULL works with single values but that only works if there is
a row returned

Does anyone know of any SQL syntax for MS SQL that when no row is
returned it makes on up and parses it back

Thank you in advance for your help!!

Ben- Hide quoted text -

- Show quoted text -
The Error Message is: exception : System.NullReferenceException:
Object reference not set to an instance of an object.

and its not really programming its a prebuilt assembly which has to be
used i can only alter the code around it, but this assembly throws an
error if there is nothing there so waht i need is, if there are no
values returned that it creats a dummy value, im not sure if you can
do that using a MS SQL statement

All that this assembly returns is either one record or nothing, pretty
useless i know :/ doesnt even return a recordset

Cheers

Ben


Reply With Quote
  #5  
Old   
Ben
 
Posts: n/a

Default Re: MS SQL for returning no values - 11-20-2007 , 09:24 AM



On 20 Nov, 14:34, Ben <bor... (AT) gmail (DOT) com> wrote:
Quote:
On 20 Nov, 13:33, Jason Lepack <jlep... (AT) gmail (DOT) com> wrote:





What language is your "Program" in? Check the recordcount on the
dataset returned and go from there, don't return the dummy record.

Cheers,
Jason Lepack

On Nov 20, 5:57 am, Ben <bor... (AT) gmail (DOT) com> wrote:

Hello,

im having a problem integrating an SQL statement with my program,
it works fine when theres a result but throws an error when there is
no result,
is there anyway in SQL to make up a row if there isnt one that matches
the query for example in this i could put indicator values in the
returned fields then a simple check to see if its a proper field of my
indicator field

I know ISNULL works with single values but that only works if there is
a row returned

Does anyone know of any SQL syntax for MS SQL that when no row is
returned it makes on up and parses it back

Thank you in advance for your help!!

Ben- Hide quoted text -

- Show quoted text -

The Error Message is: exception : System.NullReferenceException:
Object reference not set to an instance of an object.

and its not really programming its a prebuilt assembly which has to be
used i can only alter the code around it, but this assembly throws an
error if there is nothing there so waht i need is, if there are no
values returned that it creats a dummy value, im not sure if you can
do that using a MS SQL statement

All that this assembly returns is either one record or nothing, pretty
useless i know :/ doesnt even return a recordset

Cheers

Ben- Hide quoted text -

- Show quoted text -
Hey!

nevermind, my stupid brain thought of another idea, appologies for the
post it seems really stupid now >.< why didint i think of count....
Sigh

Thanks for your help anyway!

Regards

Ben


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.