I am working on an application to get data from a MS-SQL server (2005). In the command text, I can pass a sql query like this:
string query = \"SELECT T1.f1,
In general I've found it's best to use views for several reasons:
There are probably more reasons, but at this point I would never write a query directly in code.
You should also look into some kind of ORM (Object Relational Mapper) technology like LINQ to SQL (L2S). It lets you use SQL-like queries in your code but everything is abstracted through objects created in the L2S designer.
(I'm actually moving our current L2S objects to run off of views, actually. It's a bit more complicated because the relationships don't come through as well... but it's allowing me to create one set of objects that run across 2 databases, and keep everything nicely abstracted so I can change the underlying table names to fix up naming conventions. )