Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Saturday, 20 February 2016

SQL Scripting TutorialIn Feburary 2016 20,

In Feburary 2016 20,
Open up the database program of your choice. This could be Microsoft Access, SQL Server, or Oracle. Create a few sample fields, such as First Name, Last Name, Address, City, State, and Zip. Then add a few sample records to test on.
Write your first query by typing out 'SELECT
FROM table_name' where table_name is the name of the table you created. This example returns every value from every field in the table within your database (the
indicates all). You can also say 'SELECT field_name FROM table_name' to select only the field_name field from your table.
Add to your last statement with the WHERE clause. The WHERE clause specifies which fields you want to return based on a certain value. 'SELECT * FROM table_name WHERE last_name = 'Morgan' ' will search for 'Morgan' in the last_name field and returns all records from the table in which the person's last name is Morgan. Note that if you are searching for a string (letters or words), you will need single quotes around the name. If you are searching for a number, you don't need the quotes.
Add to your last statement once again by using the ORDER BY clause. 'SELECT
FROM table_name ORDER BY last_name' will order your recordset by the person's last name in alphabetical order. You can also do 'SELECT
FROM table_name ORDER BY age' and it will order by the person's age (add DESC after the field name you wish to order by to list the names in descending order).
Create a new query by typing the INSERT INTO statement. The INSERT INTO statement inserts a new row into the table that you specify. 'INSERT INTO table_name VALUES ('Courtney','Morgan',14)' will add the first name of Courtney, the last name of Morgan, and the age of 14 into your table. Likewise, if you want to delete someone from your table, you will use the DELETE statement. 'DELETE FROM table_name WHERE last_name = 'Morgan' AND first_name = 'Courtney' ' will delete Courtney Morgan from your table.
Create another new query. Use the UPDATE statement. This will update a record instead of adding or deleting one. 'UPDATE table_name SET address = '555 Hollywood Blvd', city = 'Los Angeles' WHERE last_name = 'Morgan' AND first_name = 'Courtney' ' will update Courtney Morgan's address to 555 Hollywood Blvd and her city to Los Angeles.
In Feburary 2016 20,

Sunday, 7 February 2016

How to Add Fields to a Table in Access with Visual BasicIn Feburary 2016 07,

In Feburary 2016 07,
Open Microsoft Visual Basic Express, and click 'New Project...' in the left pane of your screen. Double-click 'Console Application.' Press 'Ctrl' and 'A' and then press 'Delete' to remove the current code.
Copy and paste the following code to your 'Module1.vb' module to execute a query and add two fields to the 'Products' table in the Northwind database.Imports System.Data.OleDbModule Module1
Sub Main()Dim northwindConn As OleDbConnectionDim sqlComm As OleDbCommandDim strSQL As StringnorthwindConn = New OleDbConnection('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;')northwindConn.Open()strSQL = 'ALTER TABLE Products ' & _'ADD COLUMN Product_I Text (30), Product_II Text (30);'sqlComm = New OleDbCommand(strSQL, northwindConn)sqlComm.ExecuteNonQuery()MsgBox('Added two fields successfully to the Products table.')northwindConn.Close()End Sub
End Module
Edit the following line of code and type the path to your database:OleDbConnection('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\ Northwind 2007.accdb;')Press 'F5' to run your program.
In Feburary 2016 07,

Saturday, 6 February 2016

How to Check MySQL Null on PHPIn Feburary 2016 06,

In Feburary 2016 06,
Open your PHP source file in a text editor, such as Windows Notepad.
Use the 'mysql_query(query)' function to send a MySQL query to the active database. For example, '$result=mysql_query('Select my_var from my_table');'.
Use the 'mysql_fetch_assoc(result)' function inside a 'while' loop to fetch rows from the MySQL result. For example, 'while ($my_values=mysql_fetch_assoc($result)) {'.
Use the 'is_null(variable)' function inside the 'while' loop to determine if a field from a returned row has a NULL value. For example, if (is_null($my_values['my_var'])) { echo 'is NULL'; } }' will print 'is NULL' for any values of 'my_var' that are NULL.
Save the PHP file.
In Feburary 2016 06,