I have this sql
DECLARE @CurrentLocation geography;
SET @CurrentLocation = geography::Point(@Latitude,@Longitude,4326)
SELECT
ID,
RestaurantTitle,
CuisineName,
Latitude, Longitude,
MinimumOrder,
ImagePath,
CASE
WHEN r.OpeningTimeType IN ('24*7')
THEN r.OpeningTimeType
ELSE r.Breakfast_OpenTime
END AS OpenTime,
CASE
WHEN r.Breakfast_OpenTime > CONVERT (time, CURRENT_TIMESTAMP)
AND R.Dinner_CloseTime < CONVERT (time, CURRENT_TIMESTAMP)
THEN 'PRE ORDER'
ELSE 'ORDER NOW'
END AS BUTTONNAME,
ROUND(ROUND(GeoLocation.STDistance(@CurrentLocation), 0) / 1609.34, 0) AS Distance
FROM
[dbo].[tbl_Restaurant1] r
CROSS APPLY
(SELECT
CuisineName + ','
FROM
tbl_Cuisine
WHERE
tbl_Cuisine.ID IN (SELECT CuisineID_FK
FROM tbl_Restaurant_Cuisine
WHERE r.ID = RID_FK)
FOR XML PATH('')) D (CuisineName)
WHERE
@CurrentLocation.STDistance([GeoLocation]) <= 40000
When I ran this SQL, an exception is thrown:
Conversion failed when converting date and/or time from character string
Here are the columns:
ID int
RestaurantTitle varchar(50)
Latitude decimal(10, 6)
Longitude decimal(10, 6)
MinimumOrder int
ImagePath varchar(50)
OpeningTimeType varchar(50)
breakfast_OpenTime time
r.OpeningTimeType) with a date and/or time (r.Breakfast_OpenTime), which is probably what is producing the error. For a case statement, the values you return need to all be able to be converted to the same data type (the data type with the highest precedence). e.g. '24*7' can't be converted to a date and/or time. - ZLKr.Breakfast_OpenTimeas a varchar in the first case statement). - ZLK