Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How to retrieve all records with some field value=null

Reply
Thread Tools

How to retrieve all records with some field value=null

 
 
=?Utf-8?B?ZGF2aWQ=?=
Guest
Posts: n/a
 
      05-30-2007
I have a web services method getRecords(string name, string alias).
In the implementation, I use the following stored procedure. How can I get
the all records with alias=null. When I leave alias empty, it returns all
records with alias != null.

Thanks for any help.

David

-----
CREATE PROCEDURE searchTable4Test
(
@Name nvarchar(64),
@Alias nvarchar (64)

)
AS
Select * from Table4Test
Where name like '%'+@Name+'%' and (alias like '%'+@Alias+'%' )
RETURN @@IDENTITY
GO
------
 
Reply With Quote
 
 
 
 
Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
Guest
Posts: n/a
 
      05-30-2007
This is an ASP.NET group, not a SQL group.

But you might try this:
Where name like '%'+@Name+'%' and (IsNull(alias,'') like '%'+@Alias+'%' )

The second parameter sent to the SQL Server IsNull function is an empty
string. This tells SQL Server to convert nulls to empty strings when doing
the evaluation.

Another approach might be something like this:
Where name like '%'+@Name+'%' and (alias like '%'+@Alias+'%' or alias is
null)

Here are more examples:
http://www.lakesidesql.com/articles/?p=6

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net


"david" <> wrote in message
news:40B3C8A3-A9BE-4BDD-813D-...
>I have a web services method getRecords(string name, string alias).
> In the implementation, I use the following stored procedure. How can I get
> the all records with alias=null. When I leave alias empty, it returns all
> records with alias != null.
>
> Thanks for any help.
>
> David
>
> -----
> CREATE PROCEDURE searchTable4Test
> (
> @Name nvarchar(64),
> @Alias nvarchar (64)
>
> )
> AS
> Select * from Table4Test
> Where name like '%'+@Name+'%' and (alias like '%'+@Alias+'%' )
> RETURN @@IDENTITY
> GO
> ------


 
Reply With Quote
 
 
 
 
=?Utf-8?B?ZGF2aWQ=?=
Guest
Posts: n/a
 
      05-30-2007
Thanks, Steve.

I will try it.

David

"Steve C. Orr [MCSD, MVP, CSM, ASP Inside" wrote:

> This is an ASP.NET group, not a SQL group.
>
> But you might try this:
> Where name like '%'+@Name+'%' and (IsNull(alias,'') like '%'+@Alias+'%' )
>
> The second parameter sent to the SQL Server IsNull function is an empty
> string. This tells SQL Server to convert nulls to empty strings when doing
> the evaluation.
>
> Another approach might be something like this:
> Where name like '%'+@Name+'%' and (alias like '%'+@Alias+'%' or alias is
> null)
>
> Here are more examples:
> http://www.lakesidesql.com/articles/?p=6
>
> --
> I hope this helps,
> Steve C. Orr,
> MCSD, MVP, CSM, ASPInsider
> http://SteveOrr.net
>
>
> "david" <> wrote in message
> news:40B3C8A3-A9BE-4BDD-813D-...
> >I have a web services method getRecords(string name, string alias).
> > In the implementation, I use the following stored procedure. How can I get
> > the all records with alias=null. When I leave alias empty, it returns all
> > records with alias != null.
> >
> > Thanks for any help.
> >
> > David
> >
> > -----
> > CREATE PROCEDURE searchTable4Test
> > (
> > @Name nvarchar(64),
> > @Alias nvarchar (64)
> >
> > )
> > AS
> > Select * from Table4Test
> > Where name like '%'+@Name+'%' and (alias like '%'+@Alias+'%' )
> > RETURN @@IDENTITY
> > GO
> > ------

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
Populate Hidden field on post back and retrieve value from Hidden Field Rick ASP .Net 3 04-13-2010 05:38 PM
Simple query returns 0 records in asp, but all records in vbscript masg0013@gmail.com ASP General 3 11-02-2006 09:23 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57