The best way is to use stored procedures if you are using SQL server or Oracle. If not then use an sql string.