Ask a Question related to Coldfusion Database Access, Design and Development.
-
noah_britton #1
Ignoring blank input parameter in a stored procedure
I'm trying to write a SP that ignores a blank parameter in a where clause like
this.
create procedure blah @myvar int AS
select * from companies
where 1 = 1
if @myvar is <> ''
and id = @myvar
This seems like a simple task but it doesn't work. Thanks in advance
noah_britton Guest
-
#40143 [Opn->Bgs]: how to get parameter values of stored procedure.?
ID: 40143 Updated by: tony2001@php.net Reported By: hd4_all at yahoo dot co dot in -Status: Open +Status: ... -
#40143 [NEW]: how to get parameter values of stored procedure.?
From: hd4_all at yahoo dot co dot in Operating system: windows 2000 prof. PHP version: 5.2.0 PHP Bug Type: MySQLi related... -
populate datagrid with stored procedure w/parameter
All, I'm trying to populate a datagrid with a data adapter that uses a stored procedure with a parameter. I get the below error when I run my... -
Stored Procedure/Parameter problem
I'm getting an error I don't understand.... Here's my Code: Dim dr As SqlDataReader Dim retVal As Boolean = False Dim MySQL as string =... -
Called a Stored Procedure , decimal parameter
I have a stored procedure with a decimal parameter . how can send the decimal value? I try this but it gives an error , invalid cast specified. ... -
paross1 #2
Re: Ignoring blank input parameter in a stored procedure
Assumint SQL Server, try something like this:
SELECT *
FROM companies
WHERE id = ISNULL(@myvar, id)
If your @myvar parameter is NULL, then your WHERE clause is basically <b>id =
id</b>, which makes it a "don't care" condition and returns all rows as if
there was no where clause.
Phil
paross1 Guest
-
noah_britton #3
Re: Ignoring blank input parameter in a stored procedure
Yes, I'm working with SQL Server. The code you posted tworks if the parameter is Null, but what if it is passed as a blank string?
Thanks,
Noah
noah_britton Guest
-
paross1 #4
Re: Ignoring blank input parameter in a stored procedure
Try it....shouldn't make any difference.
paross1 Guest
-
MikerRoo #5
Re: Ignoring blank input parameter in a stored procedure
Use the ISNULL trick but at the top of your stored procedure add the line:
<b>IF LTRIM (@myvar) = '' SET @myvar= NULL</b>
MikerRoo Guest



Reply With Quote

