sql - converting function to stored procedure -


i'm working in app has user functions throughout where clauses in data layer, , i'm sure it's causing problems performance.

as example, let's there's report pulling entries , comments, , there's function

where (dbo.countcomments(entries.id, '5/10/2011') = 0) 

...showing us, let's say, entries no comments today.

i'd convert stored proc, seems it's impossible same behavior stored proc.

if had rewrite sp, how it?

a couple of thoughts.

first, using count=0 find out of there none of inefficient. you're better off using

not exists (select...) 

that way sql can bail finds row return false instead of having visit of them return non-zero count.

second, using function in queries? if want ot use output query criteria in example you're not going able stored procedures.

what find myself doing writing functions or views commonly-used queries , wrap of them in stored procedures when want return rows return. if have join results against other tables or views, it's best leave them functions.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -