May 5, 2012 at 12:10 am
Hello I am currently in school and am having some troubles with part of an assignment.
Write a user-defined function (UDF) that calculates a student's GPA for a given time frame. Inputs are StudentId int, ClassStartDateStart datetime, and ClassStartDateEnd datetime. The output should be the student's GPA for all classes that were taken between ClassStartDateStart and ClassStartDateEnd. Also, supply the script to call this new function, passing it parameter values of your choice.
From what Ive looked at you have to use another language such as C to do a udf maybe I'm not searching for the right information. I don't know anything about C haven't covered anything like that yet. Could some one help clarify what they are looking for?
May 5, 2012 at 3:24 am
User defined functions are written in T-SQL, definitely not in C or C++.
In Books Online (or the MSDN documentation), look up CREATE FUNCTION.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 5, 2012 at 4:51 am
You have got yourself confused with User Defined Functions and User Defined CLR Functions.
What you are trying to do can be done using a simple USER DEFINED FUNCTION
What you are implying when you say C, C++ code that is a CLR Function
I hope Gail agrees with me this time.....:-D
May 5, 2012 at 5:15 am
vinu512 (5/5/2012)
What you are implying when you say C, C++ code that is a CLR Function
Well, not quite. C++ is used for extended procedures (for anyone that brave). CLR procedures/functions/etc are written in C# or VB.net
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
May 5, 2012 at 10:01 pm
Thanks for your help, will look into create function.
May 7, 2012 at 1:07 pm
lil_emery13 (5/5/2012)
Thanks for your help, will look into create function.
Can you please confirm you're platform is SQL Server, and that the version you'll be developing for is SQL Server 2008?
I am not sure you need to use the SQLCLR object to accomplish this task. A T-SQL UDF of some sort should handle the request just fine.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
May 7, 2012 at 4:39 pm
I am using MySQL through phpMyAdmin. Sorry for not clarifying.
May 7, 2012 at 4:44 pm
lil_emery13 (5/7/2012)
I am using MySQL through phpMyAdmin. Sorry for not clarifying.
No problem. This website is devoted to Microsoft SQL Server. While current versions of MySQL support User-defined Functions the SQL dialect implemented there is different from what is supported by SQL Server. You may have better luck posting your question on a website dedicated to MySQL...Oracle Technet and PlanetMySQL are a couple decent options. StackOverflow is also good for most things.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply