Friday, March 9, 2012

How to use if else

Dear friends,

I have a webpage having a textbox and combobox. Combobox contains messers and country. If a user for instance enter?'India'?in?textbox?and?select?country?in?combobox.?I?want?to?retrieve?records?having?India?in?their?country?field.?
And?if?user?inputs?category?data in?textbox?and?select?category?from?combo?it?should?be?shown?that?category?records.?But?

It is giving error "Procedure or Function 'search' expects parameter '@.messers', which was not supplied."

ALTER PROCEDURE [dbo].[search]
@.messers nvarchar(70),
@.country nvarchar(20)

AS
IF @.country <> ''
BEGIN
select * from vendor where country like '%' +@.country+'%'
END
ELSE
IF @.messers <> ''
BEGIN
select * from vendor where messers like '%' +@.messers+'%'
END

Any help. PleaseYou need to set the default values for the parameters in the proc. Otherwise SQL Server expects you to send in BOTH parameters. Also I would add the condition @.param IS NOT NULL to make sure its not NULL. Checking for empty string is not sufficient.

ALTER PROCEDURE [dbo].[search]@.messersnvarchar(70)NULL,@.countrynvarchar(20)NULLASBEGINIF @.country <>''AND @.countryISNOT NULLBEGINselect *from vendorwhere countrylike'%' +@.country+'%'ENDELSEIF @.messers <>''AND @.messersISNOT NULLBEGINselect *from vendorwhere messerslike'%' +@.messers+'%'ENDEND

No comments:

Post a Comment