son Posted April 4, 2004 Posted April 4, 2004 heya can someone help .. i am using vb.net in my aspx.vb file i am writing code with SQL i keep on getting an error message say the CAST expects AS thanks in advance sonia " SELECT Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' AS Vehicle," & _ " (cast (Cast(CAN_Message.Distance * " If Session("user_Miles") = True Then strSQL += "0.6214)as decimal(10,2)) as nvarchar) + 'm') as distance, " Else strSQL += "1.0000)as decimal(10,2)) as nvarchar) + 'km') as distance, " End If strSQL += _ " (cast (CAST(CAN_Message.Fuel_Consumption * " If Session("user_miles") = True Then strSQL += "4.546)as decimal(10,2)) as nvarchar) + 'gallons') as Fuel_Used, " Else strSQL += "22)as decimal(10,2))as nvarchar) + 'litres') as fuel_used ," End If strSQL += _ " (cast (Cast(CAN_Message.Fuel_Consumption / CAN_Message.Distance / " If Session("user_Miles") = True Then strSQL += "1) as decimal(10,2)) as nvarchar) + ' mpg ') as Consumption_Rate " Else strSQL += "100) as decimal(10,2)) as nvarchar) + ' lts/100km ') as Consumption_Rate " End If strSQL += _ " FROM CAN_Message INNER JOIN " & _ " Mobile ON CAN_Message.Locator_ID = Mobile.Mobile_ID " & _ " WHERE CAN_Message.Locator_Id IN (" & strMobileList & ") " & _ " AND CAN_Message.Creation_Date >=" & strSQLFromDateTime & " AND Creation_Date<=" & strSQLToDateTime & _ " GROUP BY Mobile.Label + ' ( ' + Mobile.Registration + ' / ' + CAST(CAN_Message.Locator_ID AS varchar(5)) + ' )' " Quote
Moderators Robby Posted April 4, 2004 Moderators Posted April 4, 2004 Have you done a step-through of strSQL and executed directly on the database, i.e. Query Analyzer A couple of your CASTs don't look right. Quote Visit...Bassic Software
Joe Mamma Posted April 7, 2004 Posted April 7, 2004 Hi sonia. . . I think you have an extra '(' before some of the casts: " (cast (Cast(CAN_Message.Distance * " also your group by statement is underqualified Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.