I am trying to execute the following SQL query:
SELECT TMP.*,COUNT(*) OVER () AS rCount
FROM (
SELECT venueID,
venueName AS venueName,
venueSpanish AS spanish,
venueAddress + ', ' + venueCity + ', ' + venueState + ' ' + venueZip AS venueAddress,
venueLatLong AS coordinates,
CONVERT(VARCHAR, venueEventDate, 101) + ' @ ' + CONVERT(VARCHAR,venueTime) AS dateAndTime,
SUBSTRING(venueLatLong, 1, CHARINDEX(',', venueLatLong)-1) AS Lat,
SUBSTRING(venueLatLong, CHARINDEX(',', venueLatLong) + 1, 1000) AS Lng,
(round(3959 * acos (cos(radians('35.0935409')) *
cos(radians(SUBSTRING(venueLatLong, 1, CHARINDEX(',', venueLatLong)-1))) *
cos(radians(SUBSTRING(venueLatLong, CHARINDEX(',', venueLatLong) + 1, 1000)) -
radians('-85.0856761')) +
sin(radians('35.0935409')) *
sin(radians(SUBSTRING(venueLatLong, 1, CHARINDEX(',', venueLatLong)-1)))), 1, 1)) AS distance
FROM meetUpMarkers) TMP
WHERE distance < 30
However, I am getting this as an error when doing so:
Msg 537, Level 16, State 2, Line 1
Invalid length parameter passed to the LEFT or SUBSTRING function.
Any help would be great to solve this issue!