我需要根据SQL结果创建CSV文件。但是,我没有设法合并查询以产生一个结果。有人可以帮助我吗?
这是第一个查询。
Select
Vessel.Name, Vessel.Code, PositionCurrent.Latitude,
PositionCurrent.Longitude, PositionCurrent.FixTime
From
Vessel
Inner Join
PositionCurrent ON Vessel.ID = PositionCurrent.VesselId
第一个查询结果:
Name | Code | Latitude | Longitude | FixTime
----------+-----------+----------+-------------+---------------------
477852800 | 477852800 | 1.637975 | 104.6479433 | 2017-07-07 23:25:23
Manyplus | 584552215 | 1.87415 | 102.5528412 | 2016-05-03 15:27:58
这是第二个查询。我只是设法对单个查询进行了此操作。
DECLARE @g geometry;
SET @g = geometry::STPointFromText('POINT ('+PositionCurrent.Longitude+'
'+PositionCurrent.Latitude+')', 4326);
Select Country
From [eztble].[dbo].[EEZ_1]
where geom.STIntersects(@g) = 1;
结果仅显示县名
Singapore
有人可以帮我对上面所有表格进行完整的计算,以便结果像下面吗?
Name --------Code ------- Latitude --- Longitude ----- FixTime ----------------- Country
477852800 | 477852800 | 1.637975 | 104.6479433 | 2017-07-07 23:25:23 | Singapore
Manyplus | 584552215 | 1.87415 | 102.5528412 | 2016-05-03 15:27:58 | Indonesia
谢谢。
答案 0 :(得分:0)
只需在您的第一个查询中设置@g即可:
Select Vessel.Name, Vessel.Code, PositionCurrent.Latitude, PositionCurrent.Longitude,
PositionCurrent.FixTime,geometry::STPointFromText('POINT ('+PositionCurrent.Longitude+'
'+PositionCurrent.Latitude+')', 4326) as g From Vessel
Inner Join PositionCurrent ON Vessel.ID = PositionCurrent.VesselId
,然后将其与第二张表连接。
Select Vessel.Name, Vessel.Code, PositionCurrent.Latitude, PositionCurrent.Longitude,
PositionCurrent.FixTime,Country From Vessel
Inner Join PositionCurrent ON Vessel.ID = PositionCurrent.VesselId
Inner Join [eztble].[dbo].[EEZ_1] on
geom.STIntersects(geometry::STPointFromText('POINT ('+PositionCurrent.Longitude+'
'+PositionCurrent.Latitude+')', 4326))=1;