MS SQL for returning no values
MS SQL for returning no values
am 20.11.2007 11:57:06 von Ben
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
Re: MS SQL for returning no values
am 20.11.2007 14:31:40 von helmut woess
Am Tue, 20 Nov 2007 02:57:06 -0800 (PST) schrieb Ben:
> 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 ??
> 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
Re: MS SQL for returning no values
am 20.11.2007 14:33:49 von jlepack
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 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
Re: MS SQL for returning no values
am 20.11.2007 15:34:00 von Ben
On 20 Nov, 13:33, Jason Lepack 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 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
Re: MS SQL for returning no values
am 20.11.2007 16:24:13 von Ben
On 20 Nov, 14:34, Ben wrote:
> On 20 Nov, 13:33, Jason Lepack 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 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! :D
Regards
Ben