Finally Fixed the SQL