{"id":21,"date":"2010-06-22T20:39:44","date_gmt":"2010-06-22T20:39:44","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=21"},"modified":"2022-02-17T07:14:16","modified_gmt":"2022-02-17T07:14:16","slug":"general-select-statements","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/sql-server\/queries-microsoft-sql-server\/select-statements\/general-select-statements","title":{"rendered":"General Select Statements"},"content":{"rendered":"<pre><code>\r\n\"SELECT * FROM tblTest\"\r\n\"SELECT SupplierID, CompanyName FROM dbo.Suppliers;\"\r\n\"SELECT AuthorID, LastName, FirstName FROM Authors\"\r\n\"SELECT * FROM tblUsers WHERE UserId=\" + Convert::ToString(UserId)\r\nWHERE\r\n<\/code><\/pre>\n<h4>Multiple SELECT&#8217;s<\/h4>\n<pre><code>\r\n\"SELECT SomeColumnName, SomeOtherColumnName FROM SomeTableName WHERE ...\r\n<\/code><\/pre>\n<h4>SELECT AS<\/h4>\n<pre><code>\r\n\"SELECT SomeColumnName AS 'The Name I Want To Use' FROM SomeTableName WHERE ...\r\n<\/code><\/pre>\n<h4>Multiple WHERE&#8217;s<\/h4>\n<pre><code>\r\n\"SELECT * FROM SomeTableName WHERE SomeColumnName=24 AND SomeColumnName=15\"\r\n<\/code><\/pre>\n<h4>NULL Records<\/h4>\n<pre><code>\r\n\"SELECT * FROM tblUsers WHERE DeletedDateTime IS NULL ORDER BY UserName ASC\";\r\n\"SELECT * FROM tblUsers WHERE DeletedDateTime IS NOT NULL ORDER BY UserName ASC\";\r\n<\/code><\/pre>\n<h4>DateDiff<\/h4>\n<pre><code>\r\nSqlCommand1-&gt;CommandText = \"SELECT * FROM tblRecordings WHERE DATEDIFF(second, EndDateTime, '\" + StartDateTime-&gt;ToString() + \"') = 0\"; \/\/Datediff seems to work for days etc, but this example just doesn't work for some reason\r\n<\/code><\/pre>\n<h4>Matches A Value In A List Of Values<\/h4>\n<pre><code>\r\n\"WHERE MyColumnName IN (1,3,6,8)\"\r\n\"WHERE MyColumnName IN ('Monday','Wednesday','Saturday')\"\r\n\"WHERE MyColumnName NOT IN ('Monday','Wednesday','Saturday')\"\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;SELECT * FROM tblTest&#8221; &#8220;SELECT SupplierID, CompanyName FROM dbo.Suppliers;&#8221; &#8220;SELECT AuthorID, LastName, FirstName FROM Authors&#8221; &#8220;SELECT * FROM tblUsers WHERE UserId=&#8221; + Convert::ToString(UserId) WHERE Multiple SELECT&#8217;s &#8220;SELECT SomeColumnName, SomeOtherColumnName FROM SomeTableName WHERE &#8230; SELECT AS &#8220;SELECT SomeColumnName AS &#8216;The Name I Want To Use&#8217; FROM SomeTableName WHERE &#8230; Multiple WHERE&#8217;s &#8220;SELECT * FROM SomeTableName WHERE [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-21","post","type-post","status-publish","format-standard","hentry","category-select-statements"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/21","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=21"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/21\/revisions"}],"predecessor-version":[{"id":1510,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/21\/revisions\/1510"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=21"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=21"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=21"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}