July 14, 2006 at 8:20 am
I have just read about user defined functions. I am trying to imagine what functions I might want to create. This is my list:
Do these seem reasonable. None of the items can be used within a select statement so would there be any point in having them as functions?
One exception. If I wanted to suppress data, which did not reach a critical value, could I then call a function to do this suppression for me? I could then set the suppression level depending on who was retrieving the data.
Does anyone have prewritten functions for any of these tasks and which on my list cannot be realistically created?
July 14, 2006 at 10:31 am
As you say, there's no great adavatage to using a function for much of this stuff as it won't be used in a SQL statement. In other cases, there are more specific points which apply:
1. a UDF can't have side effects, so updates inserts deletes and DDL aren't allowed.
2. a UDF can't use dynamic SQL, so you won't be able to write code which determines DDL of target objects at runtime in order to generate SQL.
see point 2.
see point 2 - since you would need to find out which character columns were in the table in order to generate the SQL.
Hard to do as sysdepends is not (ahem) dependable and you would have to use
select *
from syscomments c
left join syscomments c2
on c.id = c2.id
and c.colid = c2.id + 1
where isnull(c2.text,'') + c1.text like '% + @tabname + '%'
But this isn't reliable since the string could be quoted or commented or part of another string rather than a refrence to the specified table.
As above
sysobjects and syscolumns have this info.
See point 2
See point 2 - if the names of the DBS are to be specified as arguments to the function
sysconstraints, syscolumns should do it I think.
See points 1 and 2
See points 1 and 2
Tim Wilkinson
"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
July 16, 2006 at 2:48 pm
Wow, Mark... that's quite the laudry list...
There are many solutions (and caveats as Tim pointed out) to your list of nice-to-haves... if you do a search on this site, I'm pretty sure you'll find most of them. This forum doesn't have a real advanced search but you'll get the hang of it in short order.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply