Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-10-17 : 08:17:20
|
| Hi,In the stored proc below, i may or may not pass the two parameters.It seems what I have does not return the correct data.How should I change the where clause in the end select statement please?Thankscreate procedure myProc@Name varchar(5) = null,@Code char(4) = nullas...declare @ClassID tinyintselect @ClassID = ClassID from tblMain where Name = @Nameselect...where (a.ClassID = @ClassID or @ClassID =0 and c.Code = @Code or @Code is null) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-17 : 08:27:10
|
it should be ...where ((a.ClassID = @ClassID or @ClassID is null)and (c.Code = @Code or @Code is null)) ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-10-17 : 08:31:06
|
| Hi,please note that I should have said, I may pass one or two or no parameters.The where clause still does not return the correct data.Any thoughts please?Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-17 : 08:35:16
|
| as per your current proc, if you do not pass a parameter it will assume null value and since @ClassID is assigned value based on @Name it will be null for @Name = null and so query should work fine with where clause provided.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-10-17 : 08:41:42
|
| Many thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-17 : 09:02:42
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|