Showing posts with label Select. Show all posts
Showing posts with label Select. Show all posts

Sunday, 27 September 2009

Display information in Upper and Lower case from SQL database

In my database table (products) I have a column called items that lists a number of products in sentence case. In order to display them in upper and lower case I do the following :

Open query analyser.
Select the required database.

Upper case

Select upper (item) from products

Lower case

Select lower (item) from products

Get current date and time in SQL

There may be times where you will need to insert the current date and time into a database i.e. to record when a transaction has taken place. The command to display this timestamp is as follows :

select getdate() 'Current Date'

If you type this into query analyser you will get the current date and time in a column entitled 'Current Date'.

How do you copy a database table in SQL using code?

Open Query analyser
Select the required database (Use [databasename])

Type :

SELECT * INTO MyNewTable FROM MyTable

e.g SELECT * INTO Customer2 FROM Customer

How do you select all items from a SQL table ?

This is probably the first thing you will ever do with SQL and it's a nice easy one to get you started.

Open query analyser.
Select the required database (This can be done from the drop down menu or by typing "Use [database name"])

Type :

Select * from [table name]

This will now return all the records in the table.