Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT INTO Statement Failed

Can you guys guide me as to why this does not work?

SELECT AN.an_id, AN.an_name, 
    (SELECT TOP(1)ex_date
        FROM upd_exam_headers
        WHERE HS.an_id = AN.an_id
        ORDER BY ex_date desc), 
        sum(ex_fee)
INTO upd_nc_felines AS FS
FROM upd_animals AS AN
LEFT JOIN upd_exam_headers AS HS ON HS.an_id = AN.an_id
LEFT JOIN upd_exam_details AS DS ON DS.ex_id = HS.ex_id
WHERE an_type = 'cat' and an_status = 'NC'
GROUP BY AN.an_id, AN.an_name;

Msg 156, Level 15, State 1, Line 10 Incorrect syntax near the keyword 'AS'.

like image 985
Le_RedditUser Avatar asked May 06 '26 20:05

Le_RedditUser


1 Answers

The error message says what it means :)

Add an alias to sum(ex_fee)

like image 195
Pred Avatar answered May 11 '26 14:05

Pred