Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 User Defined Function

Author  Topic 

Cass
Starting Member

9 Posts

Posted - 2009-04-17 : 03:25:32
Hello!

Is it possible to do this in SQL server with Function?

VBA code is
Function getparams(sKey As String, Optional sTable As String = "Params") As Variant
Select Case DLookup("type", sTable, "Key='" & sKey & "'")
Case "N": getparams = DLookup("Nr", sTable, "Key='" & sKey & "'")
Case "A": getparams = DLookup("Time", sTable, "Key='" & sKey & "'")
Case "T": getparams = DLookup("Text", sTable, "Key='" & sKey & "'")
Case Else:
getparams =''
End Select
End Function


Table looks:
ParamsID | Key | Type | Nr |   Time   | Text
1 val1 N 10
2 val2 T 17.04.2009
3 val3 A Some text


And if i'm using in SQL getparams('val2') then return 17.04.2009
Or getparams('val1') then return 10

For example:
SELECT (getparams('val1')-Limit) AS NumberFormatValue, getparams('val2') AS DateFormatValue
FROM Limits


Sorry if it is stupid question

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-04-17 : 10:25:14
didnt understand how you will get values of different datatype returned from same function.
Go to Top of Page
   

- Advertisement -