"SELECT * FROM tblTest"
"SELECT SupplierID, CompanyName FROM dbo.Suppliers;"
"SELECT AuthorID, LastName, FirstName FROM Authors"
"SELECT * FROM tblUsers WHERE UserId=" + Convert::ToString(UserId)
WHERE

Multiple SELECT’s


"SELECT SomeColumnName, SomeOtherColumnName FROM SomeTableName WHERE ...

SELECT AS


"SELECT SomeColumnName AS 'The Name I Want To Use' FROM SomeTableName WHERE ...

Multiple WHERE’s


"SELECT * FROM SomeTableName WHERE SomeColumnName=24 AND SomeColumnName=15"

NULL Records


"SELECT * FROM tblUsers WHERE DeletedDateTime IS NULL ORDER BY UserName ASC";
"SELECT * FROM tblUsers WHERE DeletedDateTime IS NOT NULL ORDER BY UserName ASC";

DateDiff


SqlCommand1->CommandText = "SELECT * FROM tblRecordings WHERE DATEDIFF(second, EndDateTime, '" + StartDateTime->ToString() + "') = 0"; //Datediff seems to work for days etc, but this example just doesn't work for some reason

Matches A Value In A List Of Values


"WHERE MyColumnName IN (1,3,6,8)"
"WHERE MyColumnName IN ('Monday','Wednesday','Saturday')"
"WHERE MyColumnName NOT IN ('Monday','Wednesday','Saturday')"
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published.