What is creating a newline in my constant?

I'm getting a "newline in constant" error in my C# after adding the TIME_FORMAT function(from MySQL), into an SQL string that I'm building and I'm not sure why or how to fix it. I tried to escape the '%' character that precedes the 'T' for the 2nd parameter of the function, but it didn't solve the problem and gave me a different error as a matter of fact. Why does it think that by adding "TIME_FORMAT("00:00:00", "%T")  to my string, that I'm adding a new line in my constant? Please help.


my MySQL string in C#
sql = String.Format(@"SELECT 
	AthleteUid, AthleteFullName, SEC_TO_TIME((SUM(TIMESTAMPDIFF(MINUTE, TimeIn, TimeOut))) * 60) AS WeekTotal, RequiredHours, SportTeamName AS SportTeam 
FROM 
	utathleteinfo uai 
    	INNER JOIN 
    utinout uio on uai.AthleteUid = uio.StudentID 
    	INNER JOIN 
    utsportteam ust ON ust.utSportTeamUid = uai.SportUid 
WHERE 
	uio.TimeOut IS NOT NULL 
    AND uio.TimeIn >= '2018-01-29 00:00:00' 
    AND uio.TimeOut <= '2018-02-02 23:59:59' 
GROUP BY 
	uai.AthleteUid, AthleteFullName, WeekTotal, RequiredHours, SportTeamName, SemesterTime, Coach 
ORDER BY 
 	AthleteFullName)
UNION
(SELECT 
	AthleteUid, AthleteFullName, TIME_FORMAT("00:00:00", "%T") AS WeekTotal, RequiredHours, SportTeamName AS SportTeam 
FROM 
	utathleteinfo uai 
    	INNER JOIN 
    utinout uio on uai.AthleteUid = uio.StudentID 
    	INNER JOIN 
    utsportteam ust ON ust.utSportTeamUid = uai.SportUid 
WHERE 
	WeekTotal = '0:00'
GROUP BY 
	uai.AthleteUid, AthleteFullName, WeekTotal, RequiredHours, SportTeamName, SemesterTime, Coach
ORDER BY 
 	AthleteFullName) ORDER BY AthleteFullName");

Open in new window


the error:

" Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1010: Newline in constant

Source Error:


Line 202:                              sql = sql + String.Format(@" UNION
Line 203:                                    (SELECT
Line 204:                                          AthleteUid, AthleteFullName, TIME_FORMAT("00:00:00", "%T") AS WeekTotal, RequiredHours, SportTeamName AS SportTeam
Line 205:                                    FROM
Line 206:                                          utathleteinfo uai "
LVL 1
Michael SterlingWeb Applications DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Ares KurkluSoftware EngineerCommented:
Hi ,

I believe you need to use double " in this case such as  TIME_FORMAT(""00:00:00"", ""%T"")
2

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
That worked. Thanks.
0
 
NorieVBA ExpertCommented:
Have you tried using single quotes instead of double quotes inside the SQL statement?
...
SELECT 
	AthleteUid, AthleteFullName, TIME_FORMAT('00:00:00', '%T') AS WeekTotal, RequiredHours, SportTeamName AS SportTeam 
FROM 
	utathleteinfo uai 
    	INNER JOIN 
    utinout uio on uai.AthleteUid = uio.StudentID 
    	INNER JOIN 
    utsportteam ust ON ust.utSportTeamUid = uai.SportUid 
...

Open in new window

1
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Michael SterlingWeb Applications DeveloperAuthor Commented:
@Norie: That was my first attempt and it didn't work. The double quotes solved it.
0
 
NorieVBA ExpertCommented:
Strange, you use single quotes in other parts of the SQL statement and when I tested it (lightly) it seemed to work fine.:)
1
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
Yeah, the whole thing threw me off. I didn't understand why it didn't work in the first place.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.