May 20, 2006 at 4:06 am
Hi guys
I created one procedure which is like this
CREATE Procedure select_Proc1
@Key3 varchar(10)
As
BEGIN
Select key3
From Or_Table
Where
END
GO
now when i execute this procedure without pass any parameter it gives me an error, what can i do when i want to see all data.
its urgent
thanx in advance
May 20, 2006 at 8:27 am
CREATE Procedure select_Proc1
@Key3 varchar(10)
As
BEGIN
IF (@key3 IS NULL)
BEGIN
Select key3
From Or_Table
END
ELSE
BEGIN
Select key3
From Or_Table
Where
END
END
May 22, 2006 at 12:14 am
hi david,
thanx for ur solution,
i solved it through this procedure
CREATE Procedure select_Proc1
@Key3 varchar(10) ='%'
As
BEGIN
Select key3
From Or_Table
Where
(key3 like @key3)
END
GO
thanx again
May 22, 2006 at 3:09 am
I'n not a big fan of using "LIKE". It slows down you queries when working wit hlarge amounts of data. This is what I would do:
CREATE Procedure select_Proc1
@Key3 varchar(10)
As
BEGIN
SELECT
tbl.key3
FROM
Or_Table tbl
WHERE
(tbl.key3 = isNULL(@key3, tbl.key3)
END
GO
May 22, 2006 at 4:57 am
One minor correction
CREATE
Procedure select_Proc1
@Key3 varchar(10) = NULL
....
If you don't give the parameter a default value, then it's mandatory and SQL will throw an error if the sp is called without it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 22, 2006 at 6:17 am
Thanx to u all
i really did not want to use like
thanx again
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply