Last week I posted about the basic usage of SELECT when extracting data from a table:-
SELECT [columns or columns (comma separated)] FROM [a database table]
SELECT doesn’t just work on comma separated column names from a database table though. Did you know you could do this:-
SELECT 'Hello, Matt'
Try it, and then try this:-
And now this:
What I’m trying to demonstrate is that you don’t just have to supply column names or a FROM to your SELECT statements – in fact any allowable expression or value will do – this will come in handy in later tutorials. Until then try the following and see what happens:-
SELECT 'Mat' + ' ' + 'Hello'
You can even comma separate hard-coded values:-
SELECT 'This', 'Is', 'Cool', 12, 18/9
Quick quiz – what column names does T-SQL provide when you run these statements? Any ideas how you might change these?
Answers next time. In the meantime think about how what we’ve looked at today might be useful.