Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Questions re: Select Statement 2

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
US
I'm new to TSQL and am trying to interpret a segment of code originating in a view I'm examining.

The code reads as follows,"SELECT adj_id id, T2.ssn ,NULL Ceris"

Here's my questions.

1.) Am I correct in assuming that adj_id is an alias for the "id" field (since none of the tables involved has a field named "adj_id")?

2.) What does NULL Ceris indicate? "Ceris" is a field in one of the tables but does NULL exclude Ceris records with a Null value or do something else?
 
just another comment on number 1

SELECT adj_id AS id
instead of

SELECT adj_id id

would be much better since it is much clearer

how many times have you forgotten a comma? For example
SELECT EmployeeID Name
FROM.....

instead of

SELECT EmployeeID, Name
FROM.....

In my opinion the AS should be mandatory

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
Denis,

Your (first) interpretation is either wrong or unclear. If you run that SELECT statement in Query Analyzer, you get:
Code:
col1        Ceris       
----------- ----------- 
NULL        NULL

(1 row(s) affected)

I.e., the aliases are the resulting column names.
 
Thanks to both of you for your help. Just to be sure that I'm understanding the (NULL) part correctly - basically then this view should produce a column named "Ceris" containing a NULL value in every row, the number of rows being determined via the where clause specifications?

In other words, in this view "Ceris" is an alias (as opposed to a reference to the "Ceris" field already existing in of the component tables of the view)?


 
yes, that understanding is correct based on the information you gave us. Sometimes programmers do this when they want to do some other processing before filling the data in or especially in Union statements where each part of the union statement must have the same number of columns.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top