1

Topic: Creating a new function in SQL SMS

I am trying to set up a new function to report on within Recorder. The code looks OK, it is basically one of Mike's functions with a couple of changes. By default it saves to My Documents\SQL Server Management Studio\Projects. Do I need to save it somewhere else in order to use it? I assume I need to be able to get it into the list of Scalar-valued Functions within SQLSMS but can't work out how to do this. Can anyone help with this please?

Gordon Barker
Biological Survey Data Manager
National Trust

2

Re: Creating a new function in SQL SMS

Gordon,

Yes, you're right, you need to get the function into the list of Scalar-valued functions (assuming it is indeed a scalar valued function). Functions stored in the database rather than on the filesystem, so you need to use some SQL to write them into the db. Easiest way to do this is to right-click on an existing function, then 'script function as'. Screenshot:

http://i.imgur.com/AUEkd1m.png

The resulting code is pretty self explanatory. You'll need to replace the existing code with your own code and give the function its unique name. Then run the SQL and that'll write it into the database.

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

3

Re: Creating a new function in SQL SMS

Thanks Charles, managed to get it sorted. A bit of trial and error with some of the REPORT ATTRIBUTE fields and getting the permissions properties set to Execute at the end but it runs in the report wizard now.

Gordon Barker
Biological Survey Data Manager
National Trust