Skip to content

How to count non-null/non-blank values in SQL

I have data like the following: And what I want is to count the PONo, PartNo, and TrinityID fields with a value in them, and output data like this: How can I do this counting in SQL?

fetching a row in the middle of the table

Table reservation contains 500,000 records and bx_date varies from 2012-01-01 to 2013-01-01. 40,000 records in users table. bx_date is ‘date’ type. With the query above if I tried a date like 2012-08-22, It takes 8 secs. But if I tried 2013-01-01 It takes like 1 sec. What is the reason? Answer The…

Export database schema into SQL file

Is it possible in MS SQL Server 2008 to export database structure into a T-SQL file? I want to export not only tables schema but also primary keys, foreign keys, constraints, indexes, stored procedures, user defined types/functions. Also I don’t want the data to be present in this T-SQL file. Is there a…

Normalize array subscripts so they start with 1

PostgreSQL can work with array subscripts starting anywhere. Consider this example that creates an array with 3 elements with subscripts from 5 to 7: Returns: We get the first element at subscript 5: I want to normalize 1-dimensional arrays to start with array subscript 1. The best I could come up with: The s…

getting count from the same column in a mysql table?

I wanted to a count of the same field for different values for example: user{user_id, gender} Gender can have obviously male or female 🙂 i want to get count for all the males and females i.e. but im confused because they come from the same gender coloumn thanks Answer Try this for row wise result: Output: Try…

Search a whole table in mySQL for a string

I’m trying to search a whole table in mySQL for a string. I want to search all fields and all entrees of a table, returning each full entry that contains the specified text. I can’t figure out how to search multiple fields easily; here are the details: The table is “clients”. It has ab…