我想将此过程转换为UDF任何建议。我已经尝试了很多东西,但无法访问所需的结果
ALTER PROCEDURE [dbo].[spLocationforSMS]
@latt varchar(150)=null,
@lont varchar(150)
AS
BEGIN
IF OBJECT_ID('tempdb..#xml') IS NOT NULL DROP TABLE #xml
CREATE TABLE #xml ( yourXML XML )
DECLARE @URL VARCHAR(8000)
DECLARE @QS varchar(50)
SELECT @QS = '&date='+convert(varchar(25),getdate(),126)
SELECT @URL = 'http://maps.google.com/maps/api/geocode/xml?
latlng='+@latt+','+@lont+'&sensor=false' + @QS
DECLARE @Response varchar(8000)
DECLARE @XML xml
DECLARE @Obj int
DECLARE @Result int
DECLARE @HTTPStatus int
DECLARE @ErrorMsg varchar(MAX)
EXEC @Result = sp_OACreate 'MSXML2.XMLHttp', @Obj OUT
EXEC @Result = sp_OAMethod @Obj, 'open', NULL, 'GET', @URL, false
EXEC @Result = sp_OAMethod @Obj, 'setRequestHeader', NULL, 'Content-Type', 'application/x-www-form-urlencoded'
EXEC @Result = sp_OAMethod @Obj, send, NULL, ''
EXEC @Result = sp_OAGetProperty @Obj, 'status', @HTTPStatus OUT
INSERT #xml ( yourXML )
EXEC @Result = sp_OAGetProperty @Obj, 'responseXML.xml'--, @Response OUT
SELECT yourXML.value('(//GeocodeResponse/result/formatted_address)[1]','VARCHAR(MAX)') from #xml