It's easier to read SQL when it's formatted, eg:
The 'SELECT' rows (13 of them) are the columns that come back from the query and pasted into your worksheet, ie. your worksheet has 13 columns in it in the order you see them above. Just change that order in the query so that the next time you run it, the columns go into your worksheet in the order you want and you don't have to do any tedious, manual copy-and-paste of columns.
You can add extra columns at the end of the 'SELECT' part, ie. after the last column (STAR.NS_VIEW_GLOBAL NS_VIEW_GLOBAL) however, not that the columns are separated by commas. Make sure any columns you add are comma separated as well as puting a comma at the end of the current last column, ie. "STAR.NS_VIEW_GLOBAL NS_VIEW_GLOBAL
,".
You can only add columns to those in the SELECT part, that are in the 3 tables the query looks at. Those three tables are shown in the 'FROM' clause. They take the form [Database Name].[Table Name], ie. the name of the database you're querying is 'STAR'. Also note that the 'SELECT' rows take the form [Table Name].[Column Name].
Remember: you don't need to take all of the columns and you shouldn't. You should only SELECT those columns that you need.
The 'WHERE' clause places the conditions on the selection from the 3 tables such that only the rows that match the conditions will be returned to you in what Database developers/administrators call 'the Result Set'. I wouldn't recommend messing with the WHERE clause unless you know what you're doing.
I hope this helps solve your problem.
Bookmarks