is there any solution to use null values to the parameter
my sql commandtext=
"select * from info where name=@.name and surname=@.surname"
in visual basic .net
info table data=
name surname
_______ _______________
1 null
2 null
i execute my program and use this commandtext
but i cant find any solution because of the null values
what can i do at visual basic .net or at sql server to solve this
bafidi wrote:
> is there any solution to use null values to the parameter
> my sql commandtext=
> "select * from info where name=@.name and surname=@.surname"
> in visual basic .net
> info table data=
> name surname
> _______ _______________
> 1 null
> 2 null
> i execute my program and use this commandtext
> but i cant find any solution because of the null values
> what can i do at visual basic .net or at sql server to solve this
Use can use a LIKE clause instead. Always add a '%' to the end of the
parameter value and never use a NULL. You should also explicitly define
all columns you require rather than using SELECT *.
Select
Col1,
Col2
From
dbo.Info
Where
name LIKE @.Name
and
surname LIKE @.surname
I might consider using a clustered index on the surname and a
non-clustered index on name. That way, you are covered in all cases.
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||Use a WHERE clause, no?
SELECT * FROM tblInfo
where vchName = @.name AND vchSurName = @.surname
AND @.name IS NOT NULL
AND @.surname IS NOT NULL
Is that okay for U?
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:ekLjiO2wFHA.2880@.TK2MSFTNGP12.phx.gbl...
> bafidi wrote:
> Use can use a LIKE clause instead. Always add a '%' to the end of the
> parameter value and never use a NULL. You should also explicitly define
> all columns you require rather than using SELECT *.
> Select
> Col1,
> Col2
> From
> dbo.Info
> Where
> name LIKE @.Name
> and
> surname LIKE @.surname
> I might consider using a clustered index on the surname and a
> non-clustered index on name. That way, you are covered in all cases.
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
|||John Smith wrote:
> Use a WHERE clause, no?
> SELECT * FROM tblInfo
> where vchName = @.name AND vchSurName = @.surname
> AND @.name IS NOT NULL
> AND @.surname IS NOT NULL
> Is that okay for U?
Why do you need the IS NOT NULL? Nothing is equal to NULL, so you're not
going to ever get NULL values back. And what happened to the query I
posted with the LIKE clauses?
Maybe you could explain your requirements in more detail. Do you need to
be able to search for NULL values? If so, you need to use WHERE COLNAME
IS NULL syntax. If you don't need NULL values and need to search on
wildcards, then look at the example I posted.
David Gugick
Quest Software
www.imceda.com
www.quest.com
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment