Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Writing Dynamic Stored Procedure


Writing Dynamic Stored Procedure

Author
Message
Muhammad Azeem-433893
Muhammad Azeem-433893
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 19
sunil,

You can use this style too....

set @Gender = isNull('M', '_')
set @Age = isNull(22, 0)

SELECT * FROM test_EmployeeDetails
Where Gender LIKE @Gender AND Age > @Age


Thanks!
Azeem
kevin mann
kevin mann
SSC Veteran
SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)SSC Veteran (226 reputation)

Group: General Forum Members
Points: 226 Visits: 119
this does not help if you have nullable fields
Dave Ballantyne
Dave Ballantyne
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1818 Visits: 8370
Interesting.....

I can now get multiple index seeks :-D

drop proc test2 
go
create proc test2 @ProductId integer,
@ReferenceOrderID integer,
@Quantity integer
as

select *
from [Production].[TransactionHistory]
where (@productid is not null and @productid = ProductID)
or (@ReferenceOrderID is not null and @ReferenceOrderID = ReferenceOrderID)
--or (@quantity is not null and @quantity = Quantity) Uncomment This to force a scan
go

exec test2 @productid = 790,@ReferenceOrderID = NULL,@Quantity=NULL
go
exec test2 @productid = NULL,@ReferenceOrderID =61197 ,@Quantity=NULL




It seems to seek if ALL the referenced columns are indexed, but uncommenting the Quantity lookup a scan takes place.

Edit : Ive updated my blog http://sqlandthelike.blogspot.com/ with this info



Clear Sky SQL
My Blog
Muhammad Azeem-433893
Muhammad Azeem-433893
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 19
isNull funcation for nullable value ... try then reply
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search