Gary Hale

Gary Hale

  • NA
  • 32
  • 1.9k

Using this CLR TVF What does the C# Method look like (HELP)

Jan 5 2019 9:47 AM
using this CLR TVF what does the CE method(s) look like
CREATE FUNCTION [dbo].[fnAddressCoordinates](@addressLine [NVARCHAR](MAX), @city [NVARCHAR](100), @state [NVARCHAR](2), @zip [NVARCHAR](15))
RETURNS TABLE (
[address] [NVARCHAR](MAX) NULL,
[city] [NVARCHAR](MAX) NULL,
[state] [NVARCHAR](MAX) NULL,
[zip] [NVARCHAR](MAX) NULL,
[lat] [DECIMAL](18, 6) NULL,
[lon] [DECIMAL](18, 6) NULL
) WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [GoogleGeocodeAPI].[GoogleGeocodeAPI.GoogleGeocodeAPI].[AddressCoordinates]
 
 
----
 
 
Example C# code
 
[SqlFunction(FillRowMethodName = "AddressCoordinates",
TableDefinition = "address nvarchar(50), city nvarchar(50), state nvarchar(50), zip nvarchar(50), latitude Decimal, longitude Decimal")]
 
public static IEnumerable BuildArray(SqlString address, SqlString city, SqlString state, SqlString zip)
{
...
 
GeoCode Req = new GeoCode
{
address = address.ToString(),
city = city.ToString(),
state = state.ToString(),
zip = zip.ToString(),
latitude = 0,
longitude = 0
};
 
// Results
ArrayList resultCollection = new ArrayList();
resultCollection.Add(Req);
return resultCollection;