Help getting data from SQLServer with custom query in my JavaScript Application

3465
10
04-28-2016 07:49 AM
JohnRitsko
New Contributor III

Here is my current scenario.

I need to gain access to a SQL Server called say, SERVER1.  Below is the custom SQL Query that I Need to utilize in order to get the most recent GPS record.  I can't seem to figure out how to utilize this in my JavaScript Application to get this data.  Of course once I get the data I need to dig into it to get the lat/lon, convert it, then map it.  One step at a time. Perhaps using $.ajax to do a GET but not quite sure how to go about this.

SQL Query:

SELECT S.MSGTEXT
FROM [dbo].[Syslogd] S
INNER JOIN
(SELECT T.[MsgDate] AS 'MSGDATE' ,MAX(L.[MsgTime]) AS 'MSGTIME'
FROM [KiwiSysLog].[dbo].[Syslogd] L
INNER JOIN
(SELECT MAX(MSGDATE) AS 'MSGDATE' FROM [dbo].[Syslogd]) T
ON L.MsgDate = T.MSGDATE
GROUP BY T.MSGDATE) DT
ON S.MsgDate = DT.MSGDATE AND S.MsgTime = DT.MSGTIME

Results in Microsoft SQL Server Management Studio Express:

$GPGGA,222020.0,3609.839478,N,11509.243300,W,1,08,0.8,618.9,M,-18.0,M,,,9999*4F  $GPRMC,222020.0,A,3609.839478,N,11509.243300,W,1.1,302.7,270416,0.0,E,A,9999*34

I appreciate the help.

John

0 Kudos
10 Replies
JohnRitsko
New Contributor III

I way overthought what I was doing.  I registered the database on Server then utilized the QueryTask as stated.  I then created the query for the values and then pushed those into an array and converted them into lat/lon as needed then created a graphic for them and added them to the map.  Problem solved.  Thank you all for the input.

0 Kudos