query and stored procedure do the same thing but the difference is that a query should be compiled everytime the query is executed,while the stored procedure is in compiled form when executed first time.I f we use stored procedure we can avoid recompilation of the query.
stored procedure comes with some major characterstics, as it consists in pre compiled format so the performance increase during dataaccess. incase of simple query it requires to complie again and again as per user request, but here its not required due to precompile format (*compile requires only ones).
next it reduce the network traffice so impacts less burden on server and u can integrate it with different front-end applications (e.g. vb.bnet,c#,java etc) inorder to data access.
come to next, due to precompile code resides in database server it provides more security and due to complicated queries can be integrated with one form it is portable also.
every query is submited it will be compiled & then executed.where as stored procedure is compiled when it is submitted for the first time & this compiled content is stored in something called procedure cache,for subsequent calls no compilation,just execution & hence better performance than query.
By using Stored procedures we can seperate all the queries from the Business logic code.Therefore we can create a seperate layer.But while writing inline queries , all the queries have to be written (mixed up ) with the business logic code. This create problem while debugging.