How can i make this into a function, i understand you cannot use the EXEC command within a function, i will be passing a postcode var.
I want to be able to return the LAT and LNG fields in a SELECT Statement, these can be in one field if necessary or i create 2 functions for each.
declare @geo varchar(max)
declare @cmd varchar(max)
declare @lat varchar(max)
set @cmd = 'select LAT,LNG from COMBINED_LOCATIONS where KEYWORD = '''''+ @postcode + ''''''
set @geo = 'SELECT top 1 * FROM OPENQUERY(LOCATION,''' + @cmd +''')'
exec (@geo)
thanks