Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

sql server - Error in sql query Incorrect syntax near

I newbie in Microsoft Visual Studio 2008. I have a SQL query, which shows a time that had been spendeed on solving each request by every employee. Data base is Microsoft SQL Server on Windows Server 2008.

I want to find a number of requests that had been solved in a 6 hours and below in percentage terms and also a sum of all solved requests of every employee

below and above 6 hours.

This is my SQL query but while it works it produces an error:

Incorrect syntax near '>' Incorrect syntax near 'tmp_table.'

SQL Query:

SELECT id, fio, date_s, tline
         , ( cast ( tline as int) > 6 ) as 'tv' 
        , count (distinct id) as 'cid'
FROM(SELECT id, fio, date_s
     , dbo.get_work_time(date_s, date_f, '12345', '09:00', '18:00', '0')/60 AS 'tline'
     FROM Zno_speed WHERE (date_f > @date)
    GROUP BY fio  
) tmp_table
GROUP BY id, fio, date_s, tline, ( cast ( tline as int) > 6 )
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SQL Server does not have a real boolean data type and thus does not support boolean expressions like cast ( tline as int) > 6

You need to rewrite that into a case statement:

case when cast ( tline as int) > 6 then 1 else 0 end as tv

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...