How can write a SELECT statement that finds the n greatest values in a column? From what i’ve read, the TOP statement only returns the first n rows, it doesn’t take any regard to the values. For example, if a have a column with ages, i want to be able to find the 5 oldest…
Tag: SQL
Oracle Database 11g PL/SQL Programming
Product Description Design Feature-Rich PL/SQL ApplicationsDeliver dynamic, client/server PL/SQL applications with expert guidance from an Oracle programming professional. With full coverage of the latest features and tools, Oracle Database 11g PL/SQL Programming lays out each topic alongside detailed explanations, cut-and-paste syntax examples, and real-world case studies. Access and modify database information, construct powerful PL/SQL statements,…
Valid styles for converting datetime to string
I wrote this little table and procedure to help me remember what style 104 did, or how to get HH:MM AM/PM out of a DATETIME column. Basically, it populates a table with the valid style numbers, then loops through those, and produces the result (and the syntax for producing that result) for each style, given…
Use CAST (or CONVERT) to handle Null Date values in Microsoft SQL Server
In an SQL Server View, a problem is that the DateTime field has many Null values which is causing a problem with the parsing of the data in MSAccess. How to I use CAST (or CONVERT) to handle Null Date values in my SQL Server view? There is a way to use CAST or CONVERT…
MS SQL Server / SELECT clause with a CASE expression
In SQL Server, if you have a column which has NULLs and instead of nulls, if you want to display ‘Nothing’, what would you do? The following query SELECT CASE Dept_Name WHEN NULL THEN ‘Nothing’ ELSE Dept_Name END Dept_Name FROM Inventory would still display the nulls and not ‘Nothing’. Workaround:
SQL SELECT INTO Statement
The SQL SELECT INTO statement can be used to create backup copies of tables. The SQL SELECT INTO Statement The SELECT INTO statement selects data from one table, creates a new table with the exact structure and size and inserts automatically the selected data into the new table. SQL SELECT INTO Syntax We can select…