Database Reference
In-Depth Information
Figure 6-12. A misleading error from the Query Designer
Your formatted code will now look something like the code in Listing 6-19. Notice that an N has been added
to the data conversion. This N indicates that the space between the two single quotes should be considered
Unicode. Strictly speaking, there is nothing wrong with this; however, it may be confusing to someone working
with this code. Using the N symbol is well documented and can easily be researched to determine the meaning,
but it is still commonly misunderstood by developers new to SQL programming.
Listing 6-19. An Example of Code That the Query Designer Will Change Without Your Consent
SELECT au_id AS AuthorId, CAST( (au_fname+N' '+au_lname) AS nVarchar(100)) AS AuthorName, state
AS AuthorState
FROM authors
Another issue with the Query Designer is the way it formats your code. As we mentioned at the beginning of
this chapter, formatting your code consistently is the mark of a professional. If you try to format the code in the
Query Designer window, however, it will ignore what you type and change the code to what it thinks is better. Yes,
the Query Designer does have an ego.
You can always clean up the code and the conversion code after you close the Query Designer, but if you
forget this feature, it can be frustrating. Figure 6-13 shows how we reformatted the code created using the Query
Designer. We have also added a data conversion to the state column after the Query Designer closes to avoid
seeing the error in Figure 6-12 again.
 
Search WWH ::




Custom Search