SELECT Ticket_no, journey_date, Travels, route, sel_seat,
seat_opt, net_pay, name, mob, book_date, PNR_no
FROM a1_ticket
WHERE (CONVERT, GETDATE(),'-') AS [DD-Mon-YYYY], journey_date) >=journey_date1
AND (CONVERT, GETDATE(),'-') AS [DD-Mon-YYYY], journey_date) <=journey_date2
ORDER BY PNR_no DESC
答案 0 :(得分:0)
您不能在where子句
中使用AS答案 1 :(得分:0)
你的where子句很奇怪。也许你想要这样的东西。
SELECT Ticket_no, journey_date, Travels, route, sel_seat,
seat_opt, net_pay, name, mob, book_date, PNR_no
FROM a1_ticket
WHERE journey_date between @journey_date1 and @journey_date2
ORDER BY PNR_no DESC
答案 2 :(得分:0)
journey_date1
和journey_date2
是否真的在同一记录中?这会很奇怪。否则,参数/变量使用@符号,例如@journey_date1
CONVERT(<target type>, <column|expression>, <optional format>)
YYYYMMDD
,但如果可能的话,请使用前端的参数化查询,这甚至不需要任何格式化。看起来您的查询应该是这样的
SELECT Ticket_no, journey_date, Travels, route, sel_seat,
seat_opt, net_pay, name, mob, book_date, PNR_no
FROM a1_ticket
WHERE journey_date >= @journey_date1
AND journey_date <= @journey_date2
ORDER BY PNR_no DESC